RandomSF Posted March 8, 2004 Share Posted March 8, 2004 AutoIt has built-in Lower and Upper case functions. Is there an easy way to do Title Case, also known as Initial Caps? Link to comment Share on other sites More sharing options...
CyberSlug Posted March 8, 2004 Share Posted March 8, 2004 Try this:$foo = "this is some sentence" MsgBox(4096,"", _StringInitial($foo)) Exit Func _StringInitial($text) Local $i, $temp, $char, $isFirstLetter = 1 For $i = 1 to StringLen($text) $char = StringMid($text, $i, 1) If $isFirstLetter And Asc($char) >= 97 And Asc($char) <= 122 Then $tmp = $tmp & Chr(Asc($char)-32) $isFirstLetter = 0 ElseIf $char = " " Then $isFirstLetter = 1 $tmp = $tmp & " " Else $tmp = $tmp & $char EndIf Next Return $tmp EndFunc Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
Valik Posted March 8, 2004 Share Posted March 8, 2004 Do you mean every worse should start with a capital letter, like this: This Is A Test Sentence. If so, that's simple. StringSplit using space as a delimiter, If the first character of each elment is an alpha character, Run that through the upper case function and re-build the string. Link to comment Share on other sites More sharing options...
scriptkitty Posted March 8, 2004 Share Posted March 8, 2004 (edited) My version of Valik's thought: $x="If so, that's simple. StringSplit using space as a delimiter, If the first character of each elment is an alpha character, Run that through the upper case function and re-build the string." MsgBox(1,"",Title($x)) Func Title($_x) $_y="" $_title=StringSplit($_x," ") For $i=1 To $_title[0] $_y=$_y & " "& StringUpper ( StringLeft($_title[$i],1) ) & StringTrimLeft($_title[$i],1) Next Return StringTrimLeft($_y,1) EndFunc No need to determine if first letter is a letter or not, StringUpper will only campitalise letters. Edited March 8, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
CyberSlug Posted March 9, 2004 Share Posted March 9, 2004 (edited) does the 'stringsplit' method correctly capitalize "word in quotes"? My code should, though you might want to make the following change to the ElseIf-clause: ElseIf $char = " " or $char = @TAB or $char = @LF or $char = @CR Then Edited March 9, 2004 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
scriptkitty Posted March 9, 2004 Share Posted March 9, 2004 (edited) Ok here is one to play around with, copy what ever you like into the clipboard, and run this: It will capitalise pretty well for ya $x=clipget() msgbox(1,"",Titlecase($x)) Func Titlecase($_x) $y=StringLeft($_x,1) $y1=$y $out=StringUpper($y) $_x=StringTrimLeft ($_x,1) for $i=0 to Stringlen($_x) $y=StringLeft($_x,1) if asc($y1)>90 and asc($y1)<97 or(asc($y1)<65 or asc($y1)>122) then $out=$out&StringUpper($y) else $out=$out&$y endif $y1=StringLeft($_x,1) $_x=StringTrimLeft ($_x,1) next return $out EndFunc Edited March 9, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
scriptkitty Posted March 9, 2004 Share Posted March 9, 2004 (edited) Oops, I Forgot You Want Title Case, Not Only Capitalise The First Letter, So Here Ya Go: $x=clipget() msgbox(1,"",Titlecase($x)) Func Titlecase($_x) $y=StringLeft($_x,1) $y1=$y $out=StringUpper($y) $_x=StringTrimLeft ($_x,1) for $i=0 to Stringlen($_x) $y=StringLeft($_x,1) if asc($y1)>90 and asc($y1)<97 or(asc($y1)<65 or asc($y1)>122) then $out=$out&StringUpper($y) else $out=$out&StringLower($y) endif $y1=StringLeft($_x,1) $_x=StringTrimLeft ($_x,1) next return $out EndFunc example This could be234tough|to work[out]title_case,so you may#wish to adjust it? becomes This Could Be234Tough|To Work[Out]Title_Case,So You May#Wish To Adjust It? Edited March 9, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
RandomSF Posted March 9, 2004 Author Share Posted March 9, 2004 Close enough. I can munge this to my specifics. Thanks everyone. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now