PDA

View Full Version : Parsing Characters


mecha
12-22-2010, 04:29 PM
Hello All,

I need to take a capture string value and parse out each letter into a new array, so.....

$charString = "2010/12/22"

needs to become....

$charArray[0] = 2;
$charArray[1] = 0;
$charArray[2] = 1;
$charArray[3] = 0;
$charArray[4] = /;
$charArray[5] = 1;
$charArray[6] = 2;
$charArray[7] = /;
$charArray[8] = 2;
$charArray[9] = 2;

I tried tokenize but that will only get me "2010" "12" "22". Any help?

Mel would be preferred, but im not scared of Python

mecha

mlefevre
12-22-2010, 05:57 PM
python
list("2010/12 /22")
# Result: ['2', '0', '1', '0', '/', '1', '2', ' ', '/', '2', '2'] #

haggi
12-23-2010, 10:03 AM
in mel:
string $mystring = "blubb";
string $array[] = python("list(\"" + $mystring + "\")");

Joviex
12-23-2010, 07:47 PM
Just to be anal and complete, the MEL solution ( I love python, here is why):


string $charString = "2010/12/22";
string $array[];
for($index=1; $index <= size($charString); $index++)
{
$array[$index-1] = `substring ($charString) ($index) ($index)`;
}
print $array;

CGTalk Moderation
12-23-2010, 07:47 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.