Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How to find first string using split function in java script.
For Example:
I have the values "100-20101"
Just i want to split 100 seperate and 20101 is separate and store it in seperate two varaiables.
How to do this in javascript...?
Posted

ok
JavaScript
var a="100-20101";
var b=a.split("-");
var c=b[0];
var d=b[1];
 
Share this answer
 
v3
Comments
RaisKazi 24-Nov-11 7:44am    
Edited: Added "pre" tag for code-block.
You can do something like:
C#
message = "100-20101";
var word= message.split("-")
//var1 & var2 will have 100 & 20101 
var1 = word[0];
var2 = word[1];
 
Share this answer
 
do as below.

JavaScript
var str = "100-20101"; 
var result = str.split("-", 1);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900