Richard Posted December 21, 2009 Posted December 21, 2009 I want to split a string at a space position, but not if the space is contained in another string. example: $x='one two three "hello world" four' with the stringsplit function this will return: one two thee "hello world" four I want it to be: one two three hello world four Anyone has a solution for that? $x='one two three "hello world" four' $sp=StringSplit ( $x, " ") for $j=1 to $sp[0] msgbox(0,"after split",$sp[$j]) next Richard
fielmann Posted December 21, 2009 Posted December 21, 2009 try this: $x='one two three "hello world" four' $bunker = "" $sp=StringSplit ( $x, " ") for $j=1 to $sp[0] $result = StringLeft($sp[$j], 1) if $result = '"' then $bunker = $sp[$j] & " " Else msgbox(0,"after split",$bunker & $sp[$j]) $bunker="" EndIf next
Richard Posted December 21, 2009 Author Posted December 21, 2009 I want the result in the $sp array and the " removed try this: $x='one two three "hello world" four' $bunker = "" $sp=StringSplit ( $x, " ") for $j=1 to $sp[0] $result = StringLeft($sp[$j], 1) if $result = '"' then $bunker = $sp[$j] & " " Else msgbox(0,"after split",$bunker & $sp[$j]) $bunker="" EndIf next
Richard Posted December 21, 2009 Author Posted December 21, 2009 this is only correct with a string with 2 words in it: "hello world"What with "hello world it is cold"It should work with any string - all in between the "" must be treated as one.I want the result in the $sp array and the " removed
Authenticity Posted December 21, 2009 Posted December 21, 2009 #include <Array.au3> Local $sString = 'one two three "hello world" four' Local $avMatches $avMatches = StringRegExp($sString, '\G(?: |^)(?|"([^"]*)"|([^ ]+))', 3) If Not @error Then _ArrayDisplay($avMatches)
Richard Posted December 21, 2009 Author Posted December 21, 2009 Thanks, this seems magic #include <Array.au3> Local $sString = 'one two three "hello world" four' Local $avMatches $avMatches = StringRegExp($sString, '\G(?: |^)(?|"([^"]*)"|([^ ]+))', 3) If Not @error Then _ArrayDisplay($avMatches)
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