titleCase - %he original string ≠ams Christopher Lee 9:23...

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 %the following position will need to be a capital letter z = y+1; a = str1(z)>='a' & str1(z) %a = str1(z>='a' & z %I tried to account for numbers in the middle of the title but could not %figure out how to get the true values out and index those actual spots int
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %he original string %Adams, Christopher Lee (Feb 11, 2010 9:23 PM EST) Krista, yes you do. .. %need to account for it. The easiest way is to assign a vector that. .. %uses the same values as the one that let you find which letters to. .. %change, then exclude the elements whose double values are not. .. %within the range of lower case letters. str1(z) = char(str1(z) - ('a' - 'A')); s %indexes the positions following the spaces and makes the characters %capital letters if they were 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