16,554
社区成员
发帖
与我相关
我的任务
分享
namespace csdn
{
class Program
{
static void Main(string[] args)
{
string str = "B2+D2+AF2+G13+B4+400+C213+C1";
Console.WriteLine("string is:"+str);
Console.WriteLine("RowNumAdd is:"+RowNumAdd(str, 5));
}
private static string RowNumAdd(string str, int addNum)
{
foreach (Match m in Regex.Matches(str, @"[a-zA-Z]+[0-9]+"))
{
int i = Convert.ToInt32(Regex.Match(m.Value, @"[0-9]+").ToString()) + addNum;
str = str.Replace(m.Value, Regex.Match(m.Value, @"[a-zA-Z]+").Value + i.ToString());
}
return str;
}
}
}
/*
string is:B2+D2+AF2+G13+B4+400+C213+C1
RowNumAdd is:B7+D7+AF7+G18+B9+400+C218+C6
请按任意键继续. . .
*/
'strSrc= "B2+D2+AF2+G13+B4+400"
'Addnum=5
Private Function StepNum(ByVal strSrc As String, ByVal Addnum As Integer) As String
Dim digitregex As Regex = New Regex("[a-zA-Z]+[0-9]+", RegexOptions.RightToLeft)
Dim Before As String = strSrc
Dim strSub As String
Dim tmpM As Match
tmpM = digitregex.Match(Before)
While tmpM.Success
strSub = Regex.Match(tmpM.Value, "[a-zA-Z]+").Value & (Val(Regex.Match(tmpM.Value, "[0-9]+").Value) + Addnum).ToString
strSrc = strSrc.Substring(0, tmpM.Index) & strSub & strSrc.Substring(tmpM.Index + strSub.Length)
tmpM = tmpM.NextMatch
End While
Return strSrc
End Function
string str = "B2+D2+AF2+G13+B4+400+C213";
string[] text=str.Split('+');
string temp = "";
foreach(string s in text)
{
if(Regex.IsMatch(s,"[a-zA-Z]+[0-9]+"))
{
temp+=Regex.Match(s,"[a-zA-Z]+").Value+(Convert.ToInt32(Regex.Match(s,@"[0-9]+").Value)+3).ToString()+"+";
}
else
{
temp+=s+"+";
}
}
temp = temp.Substring(temp.Length - 1, 1) == "+" ? temp.Remove(temp.Length - 1) : temp;
Console.WriteLine(temp);
/*
B5+D5+AF5+G16+B7+400+C216
请按任意键继续. . .
*/
Private Function u(ByVal a As String) As String
Dim k As String = ""
For i As Integer = 1 To a.Length
k = k + o(a.Substring(i - 1, 1))
Next
Return k
End Function
Private Function o(ByVal b As String) As String
Dim r As New Regex("(^[1-9]d*$)")
If r.IsMatch(b) Then
If YN = "NO" Then
YN = "SZ"
'前面是数字
Return b
End If
If YN = "YES" Then
YN = "SZ"
'前面是数字
Return "3"
End If
Return ""
Else
Dim p As New Regex("(^[A-Za-z]+$)")
If p.IsMatch(b) Then
YN = "YES"
'前面是字母
Return b
Else
YN = "NO"
'前面是字符
Return b
End If
End If
End Function