Jump to content

stringsplit


Richard
 Share

Recommended Posts

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

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

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...