如何使用c#自动增加字母数字和特殊字符 [英] how to auto increment of alphanumeric number and special characters using c#
本文介绍了如何使用c#自动增加字母数字和特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
static float billno = 2000 跨度>;
billno = billno + 1 ;
textBox1.Text = billno.ToString();
解决方案
这个怎么样?// 解析尾随数字的给定参数,将该数字递增1。
< span class =code-comment> // 返回带有递增数字的新创建的字符串,如果没有要递增的数字,则返回null。
// 如果发生进位,则前导零用完。
// 如果没有前导零,如果发生进位,则位数增加1。
static string TryToIncrement( string 标签)
{
string result = null ;
匹配m = Regex.Match(tag, @ ^(。*?)(\d +)
跨度>);
if (m.Success){
string head = m.Groups [ 1 ]。价值;
string tail = m.Groups [ 2 ]。
string format = new string (' 0',tail.Length);
int 递增= int .Parse(tail)+ 1 跨度>;
result = head + incremented.ToString(format);
}
返回结果;
}干杯
Andi
static float billno = 2000;
billno = billno + 1;
textBox1.Text = billno.ToString();
解决方案
How about this?// Parses the given argument for a trailing number, increments that number by 1. // Returns the newly creates string with the incremented number or null if there is no number to increment. // Leading zeros are used up if a carry occurs. // If there is no leading zeros, if a carry occurs, the number of digits is increased by one. static string TryToIncrement(string tag) { string result = null; Match m = Regex.Match(tag, @"^(.*?)(\d+)
"); if (m.Success) { string head = m.Groups[1].Value; string tail = m.Groups[2].Value; string format = new string('0', tail.Length); int incremented = int.Parse(tail) + 1; result = head + incremented.ToString(format); } return result; }Cheers
Andi
这篇关于如何使用c#自动增加字母数字和特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文