开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜