Thread: String to array
View Single Post
  #2 (permalink)  
Old June 24th, 2006, 09:31 PM
richard.york's Avatar
richard.york richard.york is offline
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

It's pretty easy to do, every string has a length property with the information of how long the string is in characters. From that you can use the substring method which takes the position of the string you want. The first argument is the position of the first character within the substring offset from zero, and the second argument is the position of the last character within the substring, also offset from zero.
Code:
var $letters = [];

for (var $i = 1; $i <= $somestring.length; $i++)
{
    $letters[$i] = $somestring.substring(($i - 1), $i);
}
I have to ask, why do you want to do this?? What's the practical application?


HTH!

Regards,
Rich

--
Author,
Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results

http://www.catb.org/~esr/faqs/smart-questions.html
Reply With Quote