You can use regular expression to separate string and number.
Regex string to use:
(?<string>[A-Za-z]+)(?<number>\d+)
System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match("C001", @"(?<string>[A-Za-z]+)(?<number>\d+)");
if (m.Success)
{
Console.WriteLine("String is: " + m.Groups["string"].Value + ", Number is: " + m.Groups["number"].Value);
}
This will give you an output:
String is: C, Number is: 001
From her you can do all numeric operations on "number".
Suggestion from
yesotaso
Custom build your own class
class myInt
{
public int Value;
public static myInt operator +(myInt left,int right)
{
return new myInt() {Value=left.Value + right};
}
public override string ToString()
{
return string.Format("C{0,3:D3}",Value);
}
public bool FromString(string input)
{
System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(input, @"(?<string>[A-Za-z]+)(?<number>\d+)");
if (m.Success)
this.Value = m.Groups["number"].Value;
return m.Success;
}
}