如 字符串 0010 1000 拼接结果为 1010 。
0010 1010 拼接结果为 1010 。 相同位置的相同数字不变化 如果是0和1的话改成1 字符长度4位就可以
1.ALT+F11æå¼VBEç¼è¾å¨ï¼åå»èåï¼å·¥å ·-å¼ç¨ã
2.å¼¹åºå¼ç¨-VBAProject对è¯æ¡ï¼å¾éMicrosoft VBScript Regular EXpressions 1.0ï¼ç¹ç¡®å®ã
3.æ°å»ºä¸ä¸ªæ¨¡åï¼è¾å ¥å¦ä¸ä»£ç ï¼
Sub tsszstrqh()
Dim reg As New RegExp
Dim str As String, t, s, arr
str = Range("a1").Value
With reg
.Global = True
.Pattern = "[^0-9.]"
arr = "=" & Right(.Replace(str, "+"), Len(.Replace(str, "+")) - 1)
.Pattern = "\++"
Range("b1") = .Replace(arr, "+")
End With
End Sub
4.æALT+F8ï¼è¿è¡tsszstrqhå®ï¼æ¼ç¤ºç»æå¦ä¸å¾ï¼
温馨提示:答案为网友推荐,仅供参考
第1个回答 2014-12-01
Sub test()
Dim A, B As String
A = "0010"
B = "1010"
C = FC(A, B)
MsgBox "结果为:" & C
End Sub
Function FC(str1, str2) As String
If Len(str1) = Len(str2) Then
For i = 1 To Len(str1)
s1 = Mid(str1, i, 1)
s2 = Mid(str2, i, 1)
If s1 = s2 Then
FC = FC & s1
Else
FC = FC & "1"
End If
Next
End If
End Function本回答被提问者采纳
Dim A, B As String
A = "0010"
B = "1010"
C = FC(A, B)
MsgBox "结果为:" & C
End Sub
Function FC(str1, str2) As String
If Len(str1) = Len(str2) Then
For i = 1 To Len(str1)
s1 = Mid(str1, i, 1)
s2 = Mid(str2, i, 1)
If s1 = s2 Then
FC = FC & s1
Else
FC = FC & "1"
End If
Next
End If
End Function本回答被提问者采纳
第2个回答 2015-10-19
VBA 字符串相加替换,可以这样:
【1】可以使用以下代码:
Sub test()
Dim A, B As String
A = "0010"
B = "1010"
C = FC(A, B)
End Sub
Function FC(str1, str2) As String
If Len(str1) = Len(str2) Then
For i = 1 To Len(str1)
s2 = Mid(str2, i, 1)
If <a href= target="_blank" class="baidu-highlight">s1</a> = s2 Then
FC = FC & <a href=target="_blank" class="baidu-highlight">s1</a>
Else
FC = FC & "1"
End If
Next
End If
End Function
【2】CELLS(3,3)= CELLS(1,1) & CELLS(2,2)
【3】Sub test()
Dim sr$, arr, <a href= target="_blank" class="baidu-highlight">sr1</a>$, sr2$
sr = [F65536].<a href= target="_blank" class="baidu-highlight">End</a>(3).Value
arr = Split(sr, "\")
For i = 0 To UBound(arr)
If arr(i) = 0 Then arr(i) = 10
sr2 = <a href= target="_blank" class="baidu-highlight">Abs</a>(arr(i) - [b65536].<a href= target="_blank" class="baidu-highlight">End</a>(3).Value)
If sr2 = 10 Then sr2 = 0
<a href= target="_blank" class="baidu-highlight">sr1</a> = <a href= target="_blank" class="baidu-highlight">sr1</a> & sr2 & "\"
<a href=target="_blank" class="baidu-highlight">Next</a>
[F65536].<a href= target="_blank" class="baidu-highlight">End</a>(3).Offset(1, 0) = <a href= target="_blank" class="baidu-highlight">Left</a>(sr1, Len(sr1) - 1)
End Sub
【1】可以使用以下代码:
Sub test()
Dim A, B As String
A = "0010"
B = "1010"
C = FC(A, B)
End Sub
Function FC(str1, str2) As String
If Len(str1) = Len(str2) Then
For i = 1 To Len(str1)
s2 = Mid(str2, i, 1)
If <a href= target="_blank" class="baidu-highlight">s1</a> = s2 Then
FC = FC & <a href=target="_blank" class="baidu-highlight">s1</a>
Else
FC = FC & "1"
End If
Next
End If
End Function
【2】CELLS(3,3)= CELLS(1,1) & CELLS(2,2)
【3】Sub test()
Dim sr$, arr, <a href= target="_blank" class="baidu-highlight">sr1</a>$, sr2$
sr = [F65536].<a href= target="_blank" class="baidu-highlight">End</a>(3).Value
arr = Split(sr, "\")
For i = 0 To UBound(arr)
If arr(i) = 0 Then arr(i) = 10
sr2 = <a href= target="_blank" class="baidu-highlight">Abs</a>(arr(i) - [b65536].<a href= target="_blank" class="baidu-highlight">End</a>(3).Value)
If sr2 = 10 Then sr2 = 0
<a href= target="_blank" class="baidu-highlight">sr1</a> = <a href= target="_blank" class="baidu-highlight">sr1</a> & sr2 & "\"
<a href=target="_blank" class="baidu-highlight">Next</a>
[F65536].<a href= target="_blank" class="baidu-highlight">End</a>(3).Offset(1, 0) = <a href= target="_blank" class="baidu-highlight">Left</a>(sr1, Len(sr1) - 1)
End Sub