DaLiMan 0 Posted December 8, 2004 Hi, Is there a way to make sure a Username is written like: User Name I use an InputBox to ask a name so it could be written in different ways like: USER NAME or user name, or every other option. I was trying something with Stringsplit and StringUpper and so on, but without luck so far. (also because of my limited understanding of strings and arrays) Please help. Share this post Link to post Share on other sites
Lazycat 13 Posted December 8, 2004 You on right way - split name into parts and check each part if first letter is uppercase, and remain string is lowercase. Something like:$part = StringSplit($name, " ") If $part[0] = 2 Then If StringIsUpper(StringLeft($part[1], 1)) and StringIsLower(StringMid($part[1], 2)) Then;... right Else ;... wrong name EndifAlso in upcoming beta will be possible to use regular expressions, that should simplify this task a lot. Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Share this post Link to post Share on other sites
DaLiMan 0 Posted December 8, 2004 If I understand correctly you are checking the input on HOW the user types his name. What I want to do is leave the user his freedom and do this work for him. So a name and last name are typed by the user and then transformed into the format I want which is "Name Lastname" or if he only gives 1 name "Name" or "Lastname". Share this post Link to post Share on other sites
Lazycat 13 Posted December 8, 2004 ÎK, now I understand. This will be even simpler: Dim $proper = "" $part = StringSplit($name, " ") For $i = 1 to $part[0] $proper = StringUpper(StringLeft($part[$i], 1)) & StringLower(StringMid($part[$i], 2)) & " " Next Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Share this post Link to post Share on other sites
DaLiMan 0 Posted December 8, 2004 (edited) OK, Had to make a little change but works fine. Just have a little question to make it usefull for my app. Can we now paste the splitted string together again so the name comes back together in 1 array / string? PS: I often use the MsgBox to see what the output is, which is also the case here... PS2: your link to your auto-it site didn't work!!! $Name = "DANIEL lith" Dim $proper = "" $part = StringSplit($name, " ") For $i = 1 to $part[0] $proper = StringUpper(StringLeft($part[$i], 1)) & StringLower(StringTrimLeft($part[$i], 1)) & " " MsgBox(0, "title", $proper) Next Edited December 8, 2004 by DaLiMan Share this post Link to post Share on other sites
Lazycat 13 Posted December 8, 2004 (edited) Can we now paste the splitted string together again so the name comes back together in 1 array / string?It's already do it. Variable $proper after end of loop will contain concatenated string. Just put MsgBox after loop. It will contain one extra trailing space, so you may want to remove it.PS2: your link to your auto-it site didn't work!!!Really... Thanks, I just have not thought why it broken, because I check this before...Edit: yes, this my mistake. Should be:$Name = "DANIEL lith" Dim $proper = "" $part = StringSplit($name, " ") For $i = 1 to $part[0] $proper = $proper & StringUpper(StringLeft($part[$i], 1)) & StringLower(StringTrimLeft($part[$i], 1)) & " " Next MsgBox(0, "title", $proper) Edited December 8, 2004 by Lazycat Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) Share this post Link to post Share on other sites
DaLiMan 0 Posted December 8, 2004 So obvious, but still hard to see.Just put $proper inside the expression like you do and let him put the string back together again in the loop. ( $proper = $proper & ...)Thanx very much for helping me out here !!! Greeting,Daniel PS: Your link works fine now!!! Share this post Link to post Share on other sites
awrog 0 Posted December 8, 2004 Hello,I've found some extra information about the proper() function at: http://www.mvps.org/dmcritchie/excel/proper.htm http://englishplus.com/grammar/00000045.htmPerhaps with this information some autoit expert could write a really good proper() function (which takes into account McDonalds, van Beethoven, etc.)It's already do it. Variable $proper after end of loop will contain concatenated string. Just put MsgBox after loop. It will contain one extra trailing space, so you may want to remove it.Really... Thanks, I just have not thought why it broken, because I check this before...Edit: yes, this my mistake. Should be:$Name = "DANIEL lith" Dim $proper = "" $part = StringSplit($name, " ") For $i = 1 to $part[0] $proper = $proper & StringUpper(StringLeft($part[$i], 1)) & StringLower(StringTrimLeft($part[$i], 1)) & " " Next MsgBox(0, "title", $proper)<{POST_SNAPBACK}> Share this post Link to post Share on other sites