Sign in to follow this  
Followers 0
DaLiMan

UPPER & lower Case

8 posts in this topic

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) :idiot:

Please help.

Share this post


Link to post
Share on other sites



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
Endif

Also in upcoming beta will be possible to use regular expressions, that should simplify this task a lot.

Share this post


Link to post
Share on other sites

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

#5 ·  Posted (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 by DaLiMan

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by Lazycat

Share this post


Link to post
Share on other sites

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 !!! :D:idiot:

Greeting,

Daniel

PS: Your link works fine now!!!

Share this post


Link to post
Share on other sites

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.htm

Perhaps 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

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0