Jump to content
Sign in to follow this  
renehasp

A script to reverse two words in one line

Recommended Posts

renehasp

Trying to figure out how to make a autoit script to have one input box that I can put

"FirstName Lastname" then I hit OK button

and it out puts the

"LastName FirstName" to another string.

Any help would be appreciated with this.

I want to reverse the two words in the input box.

Thank You

Rene

Share this post


Link to post
Share on other sites
weaponx

There is no reliable way to split a whole name. What if the persons name is Mary Ann O' Flannigan, or John Jacob Jingleheimer Schmidt?

Ask for first, middle and last names seperately.

$string = "FirstName Lastname"
$reversed = StringRegExpReplace($string,"\A(.*)\h(.*)\Z", "$2 $1")
MsgBox(0,"",$reversed)

Share this post


Link to post
Share on other sites
sandin
renehasp

This is perfect! Thank you so much!

$string1 = InputBox("", "First name and Last name")
$string_Split = StringSplit($string1, " ")
$string = ""
for $i = $string_Split[0] to 1 Step -1
    if $string = "" Then
        $string &= $string_Split[$i]
    Else
        $string &= " " & $string_Split[$i]
    EndIf
Next
MsgBox(0, "ok", $string)

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  

×