If you want to split a string with multiple separators then you have to pass regex expression into split method. In below example I have used three character (, : -) as separator.
var numbers = '1,2:3-4';
var numArray = numbers.split(/,|:|-/);
CODE
<!DOCTYPE html> <html> <head> <title>jQuery With Example</title> <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { $('.btnClick').click(function () { var numbers = '1,2:3-4'; var numArray = numbers.split(/,|:|-/); for (var i = 0; i < numArray.length; i++) { alert(numArray[i]); } }); }); </script> </head> <body> <div> <button class="btnClick">Click</button> </div> </body> </html>
DISPLAY
i can not understand?
ReplyDeleteHi Aksa,
DeleteIf you want to split a string with multiple separator.
Suppose your string is "I-love-my,country,India".
In this string there are two separator dash(-) and comma(,).
Then you have to write code like this.
var allword = 'I-love-my,country,India';
var wordArray = allword .split(/,|-/);
Above split method I have used regex expression, split method return an array.
In regex expression it start and end with "/".
After that enter your each separator with "|".
hi nirbhay singh bro how can use dropdwonlist along with grid view using jquery
ReplyDeleteI admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. Day Trips From Split
ReplyDeleteI am very thankful to you that you have shared this information with us. I got some different kind of knowledge from your web page, and it is really helpful for everyone. Thanks for share it. niagra falls helicopter ride
ReplyDelete