This might do the trick for you
string str = "EXP.120.556"; //120.002.123
str = String.Join(
".",
str.Split('.')
.Take(
str.Split('.').Length - 1
)
)
+ "." +
(
Convert.ToInt32
(
str.Split('.').LastOrDefault()
) + 1
).ToString();
So here in the code the first String.Join
will join the other part of the string with .
except of the last part which you want to increament using Take
. Then Convert.ToInt32
will convert the last part of the string to a integer using LastOrDefault
and then we add 1 to it and again convert it back to string using ToString