|
|
|||||||
Does anyone have a simple script or udf that will Capitalize First Letter Of Every Word In A String? From; capitalize first letter of every word in a string. To; Capitalize First Letter Of Every Word In A String. |
||||||||
|
|
|||||||
First Option is fnProper - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=120570 Second is something I just put together with very limited testing... Code: $string="this is a string" ? $string ? UCFirst($string) function UCFirst($str) dim $arr,$i $arr=split($str," ") for $i= 0 to ubound($arr) $arr[$i]=ucase(left($arr[$i],1))+lcase(right($arr[$i],-1)) next $UCFirst=join($arr," ") endfunction |
||||||||
|
|
|||||||
Give this a try... fnProper() |
||||||||
|
|
|||||||
Damn you Allen! I get to answer 1-2 posts a year and you have to beat me to the punch. |
||||||||
|
|
|||||||
LOL. Okay I have to admit you just gave me some weird satisfaction. I remember back in the day when I was first started posting here, saying the same thing to someone else. Hey... at least I remembered your UDF and gave you top billing |
||||||||
|
|
|||||||
Thank you very much I will test it. If you have time to answer a question I would appreciate it. I have only done simple programming in the past and just started to get in to stuff using arrays. I did the code below to try to solve my problem and it didn't work. If you have time could you tell me why? $string = "hello there world" $split = Split($string, " ") For Each $i in $split $i = UCase(Left($i, 1)) + Right($i, Len($i) - 1) Next $string = Join($split[$i], " ") Thanks again. |
||||||||
|
|
|||||||
The simple answer is... its wrong (although you were on the right path) $i is one element/string of the $split array Each time through the loop you are just over writing the string $i. Nothing is really changing. If you look at my sample above, you will see I am overwriting the value in the array, and then once all the values are recreated, creating a string with the join. Clear as mud? |
||||||||
|
|
|||||||
Now I saw the difference, great thank you. |