C
Charles Law
I have a string similar to the following:
" MyString 40 "Hello world" all "
It contains white space that may be spaces or tabs, or a combination, and I
want to produce an array with the following elements
arr(0) = "MyString"
arr(1) = 40
arr(2) = "Hello world"
arr(3) = "all"
Using trim and a regular expression ("\s+"), I can reduce my string to
"MyString 40 "Hello world" all"
and with Split I can get
arr(0) = "MyString"
arr(1) = 40
arr(2) = ""Hello"
arr(3) = "world""
arr(4) = "all"
As you can see, it is not quite what I need. The spaces in "Hello world"
have been reduced to a single space, and Split does not respect the double
quotes, and splits "Hello world" over two elements.
Does anyone have an idea how I could do this? I could process the string
character by character, but I am hoping that there is a straight-forward
technique for doing it, without looping, and using some of the techniques I
already have.
TIA
Charles
" MyString 40 "Hello world" all "
It contains white space that may be spaces or tabs, or a combination, and I
want to produce an array with the following elements
arr(0) = "MyString"
arr(1) = 40
arr(2) = "Hello world"
arr(3) = "all"
Using trim and a regular expression ("\s+"), I can reduce my string to
"MyString 40 "Hello world" all"
and with Split I can get
arr(0) = "MyString"
arr(1) = 40
arr(2) = ""Hello"
arr(3) = "world""
arr(4) = "all"
As you can see, it is not quite what I need. The spaces in "Hello world"
have been reduced to a single space, and Split does not respect the double
quotes, and splits "Hello world" over two elements.
Does anyone have an idea how I could do this? I could process the string
character by character, but I am hoping that there is a straight-forward
technique for doing it, without looping, and using some of the techniques I
already have.
TIA
Charles