Edgars Steins Edgars Steins -4 years ago 95
C# Question

How to take out a number from string and convert it to int?

This is my string:

string code = "105096-07874";

And I want to get the "96" out from as an int type.
Thanks in advance!

Answer Source

If you want to get the 96 by a specific location, use this:

int res = Convert.ToInt32(code.Substring(4,2));

Please note this will only work on this case, not on strings with different length.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download