DaLiMan Posted December 8, 2004 Share 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. Link to comment Share on other sites More sharing options...
Lazycat Posted December 8, 2004 Share 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]) Link to comment Share on other sites More sharing options...
DaLiMan Posted December 8, 2004 Author Share 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". Link to comment Share on other sites More sharing options...
Lazycat Posted December 8, 2004 Share 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]) Link to comment Share on other sites More sharing options...
DaLiMan Posted December 8, 2004 Author Share 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 Link to comment Share on other sites More sharing options...
Lazycat Posted December 8, 2004 Share 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]) Link to comment Share on other sites More sharing options...
DaLiMan Posted December 8, 2004 Author Share 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!!! Link to comment Share on other sites More sharing options...
awrog Posted December 8, 2004 Share 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}> 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