Possible Duplicate:
How do I split this string with JavaScript?
how to split a string in javascript?
example str = "this is part 1 one wall this is part 2 "
now I want to split the str in 2 parts separated by word wall
so I want output to be:
st1 ="this is part 1 "
st2 ="this is part 2 "
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.
Splitting the Array Into Even Chunks Using slice() Method The easiest way to extract a chunk of an array, or rather, to slice it up, is the slice() method: slice(start, end) - Returns a part of the invoked array, between the start and end indices.
var str1 = "When I say wall I want to split";
var chunks = str1.split("wall");
alert(chunks[0]); /* When I say */
alert(chunks[1]); /* I want to split */
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With