PDA

View Full Version : characters in string -> elements in array?


jgibz
09-03-2005, 07:12 PM
if I have a string, $fred = "freddy";

is it possible to get the letters in "freddy" to be the elements of a string array like $letters[]?

as in:

$letters[0] equals "f" , $letters[1] equals "r" etc.\

Thanks alot for any help! :)

AndersEgleus
09-03-2005, 07:52 PM
Interesting that I didn't find a command for doing this (neither stringToStringArray nor tokenize could do it). Oh well, the code is simple enough:string $fred = "freddy";
string $letters [];
for ($i = 0; $i < size ($fred); $i++)
$letters [$i] = substring ($fred, $i + 1, $i + 1);

jgibz
09-04-2005, 05:43 PM
Thanks Anders ")

CGTalk Moderation
09-04-2005, 05:43 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.