I need to parse a string into an array. How do I do that?

I’ve looked at the w3c schools for JavaScript, but it talks about String “Objects”, which seem different than string variables used by ScriptCase. I need a coding example pls and Thanks.

I need the string: ‘aaa.bbb.ccc.eee’ parsed into an array populated as:

rs[0] = aaa
rs[1] = bbb
rs[2] = ccc
rs[3] = eee

Re: I need to parse a string into an array. How do I do that?

Does it has to be Javascript?
This is php but Javascript has the same function.

$string=“aaa.bbb.ccc.eee”;
$rs[0]=substr($string,0,3);
$rs[1]=substr($string,4,3);
$rs[2]=substr($string,8,3);
$rs[3]=substr($string,12,3);
print_r($rs);

Later on

Re: I need to parse a string into an array. How do I do that?

Boxer,

Try this solution:

<?php
	$myString = 'aaa.bbb.ccc.eee';
	$arrString = explode(".", $myString);
	echo $arrString[0].'<br>';
	echo $arrString[1].'<br>';
	echo $arrString[2].'<br>';
	echo $arrString[3].'<br>';
?>

Hope that helps.

Sincerely,
Masino Sinaga

Re: I need to parse a string into an array. How do I do that?

Thank you jsbinca. I forgot to mention that the dots may not always be in the same place. Example: The next string may contain zzzzz.aaaa.b.ee

I’ll have to use masino’s suggestion of the “explode”.

As you can tell, I know what I want to do,l I’m still struggling with the syntax. I’ve been going to the w3c school website for JavaScript help, but, it doesn’t mention an “explode”… it only talks about string “objects” which ScriptCase doesn’t seem to deal with.

Thanks all.

Re: I need to parse a string into an array. How do I do that?

May be next time you should go to w3school website for PHP instead? :slight_smile:
Just kidding.

Re: I need to parse a string into an array. How do I do that?

Oh, good point. I’m new to PHP, JavaScript, ScriptCase etc. I was looking in the wrong place.