faqts : Computers : Programming : Languages : JavaScript : Language Core : Strings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

38 of 48 people (79%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I split a string?

Mar 3rd, 2000 20:33
Martin Honnen,


Strings have a split method that takes a separator string or even a 
separator regular expressions as the argument and returns an array of 
substrings resulting from splits where the separator is found.
So for instance
  var s = 'Kibology for all'
  alert(s.split(' '))
splits the string s into the three words.
Or
  var s = 
   'Kibology for all.\r\nAll for Kibology.\nScriptology for all.';
  alert(s.split(/\r\n|\r|\n/));
splits the string into the lines.