tags:

views:

36

answers:

3

Hi,

I have one string which contain number and character. I need to separate number and character.I have don't have a delimiter in between.How can i do this.

enter code here

Var selectedRow = "E0";

I need to "0" in another variable.

Help me on this.

A: 
selectedRow.charAt(1)

Becomes more complex if your example is something longer than 'E0', obviously.

meder
This wouldn't work for a number >9!
Tom Gullen
@Tom Gullen - I already specified that "becomes more complex if your example is longer than E0". He didn't really mention if it goes above or not. Would have been better if he provided more samples.
meder
+1  A: 

Depends on the format of the selected row, if it is always the format 1char1number (E0,E1....E34) then you can do:

var row = "E0";
var rowChar = row.substring(0, 1);

// Number var is string format, use parseInt() if you need to do any maths on it
var number = row.substring(1, row.length);  
//var number = parseInt(row.substring(1, row.length));  

If however you can have more than 1 character, for example (E0,E34,EC5,EDD123) then you can use regular expressions to match the numeric and alpha parts of the string, or loop each character in the string.

Tom Gullen
A: 
var m = /\D+(\d+)/gi.exec(selectedRow);
var row = m.length == 2 ? m[1] : -1;
john_doe