[ACCEPTED]-Split variable using a special character in JavaScript-jquery
Accepted answer
values=i.split('*');
one=values[0];
two=values[1];
0
use string.split(separator, limit)
<script type="text/javascript">
var str="my*text";
str.split("*");
</script>
0
Just to add, the comma operator is your 1 friend here:
var i = "my*text".split("*"), j = i[0], k = i[1];
alert(j + ' ' + k);
You can use the split
method:
var result = i.split('*');
The variable result 4 now contains an array with two items:
result[0] : 'my'
result[1] : 'text'
You 3 can also use string operations to locate 2 the special character and get the strings 1 before and after that:
var index = i.indexOf('*');
var one = i.substr(0, index);
var two = i.substr(index + 1, i.length - index - 1);
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.