/ Published in: C#
Expand |
Embed | Plain Text
private int GetNumber(string str) { int length = str.Length; string output = String.Empty; int test = 0; bool err = false; for(int i=0;i<=length;i++) { try { test = Convert.ToInt32(str.Substring(i,1)); } catch { err = true; } if (!err) output += str.Substring(i,1); else break; } return Convert.ToInt32(output); }
Comments
Subscribe to comments
You need to login to post a comment.

// Maybe coding as below can pass
private int GetNumber(string str) { int length = str.Length; string output = String.Empty; int test = 0; bool err = false;