user2583498
user2583498

Reputation:

How to use Substring , to return an integer of all the values after the first char

I have an string AssetNumber that have the following format C100200. so i need to do the folloiwng:-

  1. Get all the characters after the first (e.g. 100200 using above example)

  2. Convert the substring to integer

  3. Return the integer + 1

but I do not know how to use the sub-string to get all the characters after the first char, and how to convert string into int? Any help on this will be appreciated.

Upvotes: 1

Views: 2732

Answers (1)

Maxim Zhukov
Maxim Zhukov

Reputation: 10140

var result = Int32.Parse("C100200".Substring(1)) + 1;

If you would like to have default value, if you can't parse current string:

int result;
if (!Int32.TryParse("sdfsdf".Substring(1), out result)) {
    result = 42;
}

result+=1;

Upvotes: 8

Related Questions