Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Split String into individual characters  (Read 2578 times)

0 Members and 1 Guest are viewing this topic.

Dan Peach

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 100
    • View Profile
    • Viperante - Game Development
Split String into individual characters
« on: July 07, 2012, 03:23:37 AM »

Howdy,

How can I split a string into the individual characters? Everything I've found elsewhere says that String.Split(""); should work, but it doesn't - that appears to just return the entire string.

Thanks.  :)

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Split String into individual characters
« Reply #1 on: July 07, 2012, 12:52:07 PM »

You could use a simple for loop:

Code: WME Script
  1. var str = new String("THIS IS A STRING");
  2. var arr = new Array();
  3. for(var i = 0; i < str.Length; i = i + 1){
  4.         arr[i] = str.Substr(i, 1);
  5. }
  6.  
Logged

Dan Peach

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 100
    • View Profile
    • Viperante - Game Development
Re: Split String into individual characters
« Reply #2 on: July 07, 2012, 01:57:20 PM »

Perfect! Thank you.  :)
 

Page created in 0.046 seconds with 24 queries.