I need to trim the first n alpha characters from a string.
Examples:
a123456 -> 123456
abc123456 -> 123456
abc123456def -> 123456def
Thanks in advance for any help.
I need to trim the first n alpha characters from a string.
Examples:
a123456 -> 123456
abc123456 -> 123456
abc123456def -> 123456def
Thanks in advance for any help.
Try something like this:
String output = Regex.Replace(input, @"^[^\d]+", String.Empty);
Here is how the regular expression works:
^[^\d]+
^
anchors the expression to the beginning of the string
[^\d]
is a character set matching all non-integral values
+
qualifies[^\d]
by making it match one or more times
So basically this regular expression matches all non-integral characters in a string up until an integral character is found.
static string AlphaTrimRight(string value)
{
while (!Char.IsNumber(value[0]))
value = value.Substring(1, value.Length - 1);
return value;
}