Richard Posted December 21, 2009 Share 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 Link to comment Share on other sites More sharing options...
Authenticity Posted December 21, 2009 Share Posted December 21, 2009 Link Link to comment Share on other sites More sharing options...
fielmann Posted December 21, 2009 Share 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 Link to comment Share on other sites More sharing options...
Richard Posted December 21, 2009 Author Share 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 Link to comment Share on other sites More sharing options...
Richard Posted December 21, 2009 Author Share 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 Link to comment Share on other sites More sharing options...
Authenticity Posted December 21, 2009 Share 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) Link to comment Share on other sites More sharing options...
Richard Posted December 21, 2009 Author Share 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) Link to comment Share on other sites More sharing options...
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