titleCase - %the following position will need to be a...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function str_out = titleCase(str1) %function to take one string and return the string in title case; ever %first letter in every word should be capitalized, and every other letter %should be lowercase x = str1<='Z' & str1>='A'; str1(x) = str1(x) + 'a' - 'A'; %the above two lines finds all of the uppercase letters and converts them %to lowercase letters; the first line produces a set of logicals; the %second line indexes the true positions of the logicals, takes the ACSII %value there and adds 32 y = strfind(str1,' '); %uses the function strfind to locate the positions of the spaces, because
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %the following position will need to be a capital letter z = y+1; a = str1(z)>='a' & str1(z)<='z'; b = z(a); str1(b) = char(str1(b)-('a'-'A')); %indexes the positions following the spaces and makes the characters %capital letters if they were lowercase letters in the first place % if (str1(1)>='a' & str1(1)<='z') str1(1) = char(str1(1) - ('a' - 'A')); end %the if statement is used to capitalize the first letter of the string, if %it is a char not a double, and makes it a capital letter, since it is not %preceded by a space str_out = str1; end...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 1371 taught by Professor Stallworth during the Spring '08 term at Georgia Tech.

Ask a homework question - tutors are online