Converting a string to string-array

Post Reply
source1ben
Posts: 32
Joined: Fri Nov 02, 2001 10:22 am

Converting a string to string-array

Post by source1ben »

How do you convert a string to a string-array ?

Example.

<$data = "'aaa' 'bbb' 'ccc' 'ddd' 'eee'">

Vortex recogizes this as a single entry array. I need it to have the values stored as an array - so I loop thru them.

Example.

<$data = 'aaa' 'bbb' 'ccc' 'ddd' 'eee'>

thx.
User avatar
Kai
Site Admin
Posts: 1272
Joined: Tue Apr 25, 2000 1:27 pm

Converting a string to string-array

Post by Kai »

The easiest way is with <rex> or <split>:

<rex "[^\space']+" $data>
<$data = $ret>

You may have to alter the expression depending on the possible character values for data vs. separator characters. If your values have complex or inconsistent quoting schemes, you may need to use something like <fmtcp sandcall> to handle special cases.
source1ben
Posts: 32
Joined: Fri Nov 02, 2001 10:22 am

Converting a string to string-array

Post by source1ben »

Works like a charm !

thx.
Post Reply