Example:
String num = "123";
//First argument the String and second the base.
int a = System.Convert.ToInt32(num, 10);
Another way is by using the Parse function.
Example:
int b = Int32.Parse(num);
Now, if you want a method for doing these convertions, you can take a look at the following example. For argument the String value to be converted and return the integer for it. To make it a little interesting, the String value contains non numeric characters until the position number 6, example: abbton4457
public int change(String s) {
String st = s.Substring(6);}
int x = Int16.Parse(st);
return x;
No comments:
Post a Comment