开发者

How to compare two strings and replacing different bit with - in another string

开发者 https://www.devze.com 2023-01-23 05:22 出处:网络
for example i have two strings 0000 and 0001 then 0000 0001 ---- result=000-here difference is indicated by开发者_StackOverflow中文版 - sign

for example i have two strings 0000 and 0001 then

         0000
         0001
         ----
result=  000-  here difference is indicated by开发者_StackOverflow中文版 - sign


You can compare each character in the string:

Dim s1 = "0000"
Dim s2 = "0001"

Dim result = ""

If s1.Length = s2.Length Then

    For a = 0 To s1.Length - 1

        If s1(a) <> s2(a) Then
            result &= "-"
        Else
            result &= s1(a)
        End If

    Next

End If

Result = 000-

0

精彩评论

暂无评论...
验证码 换一张
取 消