Two ways:
public static string GetNonNumericString1(string input)
{
if (String.IsNullOrEmpty(input))
return String.Empty;
System.Text.RegularExpressions.Match match =
System.Text.RegularExpressions.Regex.Match(input, "[^0-9]+");
return match.Success ? match.Value : input;
}
public static string GetNonNumericString2(string input)
{
if (String.IsNullOrEmpty(input))
return String.Empty;
int position = input.IndexOfAny(
new char[] {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'});
return position < 0 ? input : input.Substring(0, position);
}
--
Milosz
"G" wrote:
Hello,
I would like look at a user-entered string, and copy all characters starting
from the left until a number is found. As soon as a number is detected, the
copy should stop and the chracters stored in a second textfield. Sounds
simple but haven't the foggiest how to do it.
For example:
Texfield1.Text = "Bryan2000"
TextField2.Text = "Bryan"
or
TextField1.Text = "H500"
TextField2.text = "H"
or
TextField1.Text = "900TEST"
TextField2.text = ""
Any ideas?
Regards,
G.