Using JavaScript parseInt at the end of a line

I know that

parseInt(myString, 10) // "Never forget the radix"  

will return a number if the first characters in the string are numeric, but how to do it in JavaScript if I have a string like "column5" and want to increase it to the next ("column6")?

The number of digits at the end of a line is a variable.

+5
source share
6 answers
parseInt("column5".slice(-1), 10);

You can use -1 or -2 for numbers from one to two digits, respectively.

If you want to specify any length, you can use the following to return the numbers:

parseInt("column6445".match(/(\d+)$/)[0], 10);

The above will work for any length of numbers if the line ends with one or more numbers

+16
source

Try the following:

var match = myString.match(/^([a-zA-Z]+)([0-9]+)$/);
if ( match ) {
  return match[1] + (parseInt(match[2]) + 1, 10);
}

text10 text11, TxT1 Txt2 .. .

radix parseInt, parseInt magic, .

. :

http://www.w3schools.com/jsref/jsref_parseInt.asp

- text010 text9, ;).

+3

, , . , , "", - :

var precedingString = myString.substr(0, 6); // 6 is length of "column"
var numericString = myString.substr(7);
var number = parseInt(numericString);
number++;

return precedingString + number;
+2
var my_car="Ferrari";
var the_length=my_car.length;
var last_char=my_car.charAt(the_length-1);
alert('The last character is '+last_char+'.');

http://www.pageresource.com/jscript/jstring1.htm

last_char

+1
  • RegEx.

  • parseInt(), .

  • .

0
source

Just try reading the char char string by checking the ASCII code. If it is from 48 to 57, you have received your number. Try using the charCodeAt function. Then just split the line, increase the number and do it.

0
source

All Articles