Ryuji5864 Posted May 2, 2009 Posted May 2, 2009 Example: 234782349 firstname lastname email I want to take the above string and spit it off into different sections. A section for the number, firstname, lastname, email. How would I go about doing that?
junkew Posted May 2, 2009 Posted May 2, 2009 Whats wrong with reading the help file first StringSplit ( "string", "delimiters" [, flag ] ) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets
Ryuji5864 Posted May 2, 2009 Author Posted May 2, 2009 Use the StringSplit() Function.Just found that function >.> Sorry for the post.
John117 Posted May 2, 2009 Posted May 2, 2009 Example: 234782349 firstname lastname email I want to take the above string and spit it off into different sections. A section for the number, firstname, lastname, email. How would I go about doing that? #Include <Array.au3> $sString = "234782349 firstname lastname email" $OneSpace = " " ;If more than 1 space apart, add more spaces here to match. See helpfile. $array = StringSplit($sString, $OneSpace) _ArrayDisplay($array)
John117 Posted May 2, 2009 Posted May 2, 2009 Whats wrong with reading the help file first StringSplit ( "string", "delimiters" [, flag ] ) What's wrong with being nicer about it. Especially with newer members . . .
Ryuji5864 Posted May 2, 2009 Author Posted May 2, 2009 What's wrong with being nicer about it. Especially with newer members . . . What if the amount of spacing is unknown?
Authenticity Posted May 2, 2009 Posted May 2, 2009 Then you can use StringRegExpReplace and something like: #Include <Array.au3> $sString = "234782349 firstname lastname email" & @CRLF $sString &= "234782349 firstname lastname email" $sString = StringRegExpReplace($sString, '\h+', ' ') $aLines = StringSplit($sString, @CRLF, 1) For $i = 1 To $aLines[0] $array = StringSplit($aLines[$i], ' ') _ArrayDisplay($array) Next
Ryuji5864 Posted May 2, 2009 Author Posted May 2, 2009 Then you can use StringRegExpReplace and something like: #Include <Array.au3> $sString = "234782349 firstname lastname email" & @CRLF $sString &= "234782349 firstname lastname email" $sString = StringRegExpReplace($sString, '\h+', ' ') $aLines = StringSplit($sString, @CRLF, 1) For $i = 1 To $aLines[0] $array = StringSplit($aLines[$i], ' ') _ArrayDisplay($array) Next Thanks a ton!! You were the biggest help. I have one more question for you. Is it possible to change the name of the row from [0] to anything else?
Authenticity Posted May 2, 2009 Posted May 2, 2009 Mind to explain some more? Do you mean, changing $aLines[0] to something else? If so, you'll need first to check if the new something else is not exceeding the last array's subscript.
Ryuji5864 Posted May 2, 2009 Author Posted May 2, 2009 Mind to explain some more? Do you mean, changing $aLines[0] to something else? If so, you'll need first to check if the new something else is not exceeding the last array's subscript. From This [0]|General information [1]|234890934867 [2]|laskdfjnkjn1 [3]|Doe [4]|John [5]|jdoe@somethinganother.com To This |General information # |234890934867 ID |laskdfjnkjn1 Lastname|Doe Firstname|John Email |jdoe@somethinganother.com If this is not possible, I could just throw it through a 2D array
Authenticity Posted May 2, 2009 Posted May 2, 2009 Use Enum. You can give a subscript index element a meaningful name so it's index is self-explaining: Enum $GenInfo, $Num, $ID, $Lastname, $Firstname, $Email, $UpperBound ; ... For $i = 1 To $aLines[0] $array = StringSplit($aLines[$i], ' ') If UBound($array) = $UpperBound Then ConsoleWrite('General Information: ' & $array[$GenInfo] & @LF) ConsoleWrite('Member number: ' & $array[$Num] & @LF) ;.... EndIf Next Or as you mentioned, it's possible to implement it using a 2D array but the enumeration method is preferred in my opinion.
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