Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main()
- {
- /*
- increments an alpha?-numeric token by 1
- */
- var maxToken = "INV-001";
- maxToken.Dump();
- var newToken = IncrementToken(maxToken);
- newToken.Dump();
- }
- public string IncrementToken(string token)
- {
- var re = new Regex(@"(.+)(\d+)$");
- var result = re.Match(token);
- var prefix = result.Groups[1].Value;
- var digits = result.Groups[2].Value;
- int num;
- int.TryParse(token.Replace(prefix,""), out num);
- var newCode = prefix + (++num).ToString().PadLeft(digits.Length, '0');
- return newCode;
- }
Add Comment
Please, Sign In to add comment