Jump to content
Sign in to follow this  
Richard

stringsplit

Recommended Posts

Richard

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

Share this post


Link to post
Share on other sites
fielmann

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

Share this post


Link to post
Share on other sites
Richard

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

Share this post


Link to post
Share on other sites
Richard

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.