Вот, пожалуйста:
public class NumberSuffixParser
{
private static readonly Regex rxPattern = new Regex( @"^(?<number>\d+(\.\d+)?)(?<suffix>\p{L}+)$" , RegexOptions.IgnoreCase|RegexOptions.ExplicitCapture ) ;
public void Parse( string value , out decimal number , out string suffix )
{
if ( value == null ) throw new ArgumentNullException("value") ;
Match match = rxPattern.Match( value ) ;
if ( ! match.Success ) throw new ArgumentOutOfRangeException("value") ;
number = decimal.Parse( match.Groups["number"].Value ) ;
suffix = match.Groups["suffix"].Value ;
return ;
}
public decimal ParseNumber( string value )
{
decimal number ;
string suffix ;
Parse( value , out number , out suffix ) ;
return number ;
}
public string ParseSuffix( string value )
{
decimal number ;
string suffix ;
Parse( value , out number , out suffix ) ;
return suffix ;
}
}
Далее следует другой, немного более упрощенный, но довольно гибкий подход. Он с удовольствием разберет такие вещи, как «789xyz», «1234» или «abcde». Если он не находит префикс целого числа, он возвращает 0. Суффикс - это то, что следует за префиксом целого числа: если он не находит суффикс, он возвращает nil ('').
public static void Parse( string value , out int number , out string suffix )
{
number = 0 ;
int i = 0 ;
for ( i = 0 ; i < value.Length && char.IsDigit( value[i] ) ; ++i )
{
number *= 10 ;
number += ( value[i] - '0' ) ;
}
suffix = value.Substring(i) ;
return ;
}