Sign in to follow this  
Followers 0
EndFunc

String Manipulation

9 posts in this topic

I have trying to use String commands to change works around and chose certain letters. For the life of me I can't figure it out.

This is what I'm trying to do.

$String = Thumb, Tom A.

I want to change it to say

TThumb by grabbing the first initial and last name. Now ordinarily that would be easy by uising a StringTrimLeft() but what if that name changes and you don't know how long the name is but the common thing is there is always a comma separating them.. I tried to use StringSplit() in conjuction but just can't get anywhere.

Anyone know how this can be done?

Thanks


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hmm, try this:

Local $string = "Thumb, Tom A."
$LastName = StringSplit($string, ",")
$FirstLetter = StringLeft($string, 1)
$NewName = $FirstLetter & $LastName[1]
MsgBox(0,"",$NewName)

Kurt

Edited by _Kurt

Awaiting Diablo III..

Share this post


Link to post
Share on other sites

Hmm, try this:

Local $string = "Thumb, Tom A."
$LastName = StringSplit($string, ",")
$FirstLetter = StringLeft($string, 1)
$NewName = $FirstLetter & $LastName[1]
MsgBox(0,"",$NewName)

Kurt

Wow, I justed tested this and i thought the "first" position would be considered a space

$FirstLetter = StringLeft($string, 1)

so, thats why i used

StringStripWS($split[2], 8)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Same results :whistle:

Kurt


Awaiting Diablo III..

Share this post


Link to post
Share on other sites

You know it's shame, you guys make it seem so easy for something I've been trying for like 2 hours :">

THANK YOU both. :whistle:

Kurt:

By the way for some reason on your code, if change the first name to something else it will grab the beginning of the last name instead. For instance

$String = "Thumb, Bob A."

The results come back as TThumb still instead of BThumb. Just wanted to let you know. Anyhow, thanks for great headstart and reply.


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

Don't worry, in no time you will be pro at string manipulations :whistle: Oh, and use Valuater's code, his is probably more logical.

Kurt


Awaiting Diablo III..

Share this post


Link to post
Share on other sites

Hmm, try this:

Local $string = "Thumb, Tom A."
$LastName = StringSplit($string, ",")
$FirstLetter = StringLeft($string, 1)
$NewName = $FirstLetter & $LastName[1]
MsgBox(0,"",$NewName)

Kurt

I am not trying to say anything other than this code, I believe does not work.

If say the name of the person in question was = Doe, John

Your example would be DDoe.

Not saying your idea would not work with the Firstname being equal to the first char after the ,


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Nite, you make a point there.

that code takes the first letter of the last name and the last name and stitches them together.

so if you say the name is:

"a, b"

you have "aa" returned.. which is in-correct, you wish to have "ba" returned.

this line:

$NewName = $FirstLetter & $LastName[1]

should read:

$NewName = $FirstLetter & $LastName[2]

for it to return as needed .. assuming that i have gotten the idea behind the whole thing correct.

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