两个文本框,第一个输入“AB00230001”,第二个输入1000后,要求结果得到“AB00231000”。
程序怎么写???
我的个人想法是先从后面开始判断有那些字符不是字母的就转为int,
还有个建议是人上认为从前面开始判断不太好,因为我公司有的产品编码像”532111109L00001“,开头的,中间包含了一个
字母,,所以我想找个从后面判断的函数,,望高人帮忙,也想在这里,问个问题,举一反三,给C#爱好者者一个学习机会。。
程序怎么写???
我的个人想法是先从后面开始判断有那些字符不是字母的就转为int,
还有个建议是人上认为从前面开始判断不太好,因为我公司有的产品编码像”532111109L00001“,开头的,中间包含了一个
字母,,所以我想找个从后面判断的函数,,望高人帮忙,也想在这里,问个问题,举一反三,给C#爱好者者一个学习机会。。
{
string str1 = Regex.Match(source, @"[0-9]+", RegexOptions.RightToLeft).Value;
string begin = str.Substring(0, source.Length - str1.Length);
return begin + (int.Parse(str1) + num).ToString().PadLeft(str1.Length, char.Parse("0"));
}Response.Write(codeNumber("532111109L00001", 1000));
Response.Write(codeNumber("AB00230001", 1000));
{
const string sNumeric = "0123456789";
sSource = "532111109L00001";
Int32 iIndex = sSource.Length;
while (sNumeric.IndexOf(sSource[--iIndex]) >= 0) ;
return ++iIndex;
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
test te = new test();
Console.WriteLine(te.codeNumber("532111109L00001", 1000));
}
class test
{
public string codeNumber(string source, int num)
{
string str1 = Regex.Match(source, @"[0-9]+", RegexOptions.RightToLeft).Value;
string begin = str.Substring(0, source.Length - str1.Length);
return begin + (int.Parse(str1) + num).ToString().PadLeft(str1.Length, char.Parse("0"));
}
}
}
}1,上下文中不存在str再问一下,代码还要修改那里,才能使用那个构造函数