String value=a009, increment string value? | SoloLearn: Learn to code for FREE!


String value=a009, increment string value?

Input string value is string value="a009"; expected output is string output="a010";

2/7/2020 11:20:09 AM

Praveen G

1 Answer

New Answer


You can't do it directly. Extract the int part from the string as integer. Increment it and convert to string of specific length. You will need to pad the string with 0, then append the string with the alphbet part to obtain the final string. (pseudo code) str = "a009"; str1 = "a"; str2 = "009"; // convert to int int i = convert_to_int(str2); i = 9; increment it; i = 10; convert i to string and padd with 0 new tmp string = "010"; form the final string res = str1+new tmp string your res = a010;