-1

我正在做一种方法,可以返回我之前的数据和之后的数据有什么不同

Dim dataBefore As String = "Name:Alice,Age:30,Sex:Male"
Dim dataAfter As String = "Name:Alice,Age:20,Sex:Female"
mtdCompare2String(dataBefore,dataAfter)




Public Shared Function mtdCompare2String(ByVal sBefore As String, ByVal sAfter As String) As String

//what i try to do before, supposing my loop should start over here but i failed, 
//so i just removed the loop, i need someone to correct me =(

Dim intBefore As Integer = sBefore.IndexOf(",")
Dim intAfter As Integer = sAfter.IndexOf(",")
Dim sBefore As String = sBefore.SubString(0,intBefore)
Dim sAfter As String = sAfter.SubString(sAfter.IndexOf(":"),intAfter)



Dim sb As StringBuilder
sb.append(sBefore,sAfter)

return sb.toString     

End Function

预期结果

年龄:30>20,性别:男>女

4

1 回答 1

2

像这样的东西应该工作:

Public Shared Function mtdCompare2String(ByVal sBefore As String, ByVal sAfter As String) As String

    'what i try to do before, supposing my loop should start over here but i failed, 
    'so i just removed the loop, i need someone to correct me =(

    Dim Before() As String = sBefore.Split(",")
    Dim After() As String = sAfter.Split(",")
    Dim ReturnString As String = ""
    For I = 0 To Before.Length - 1
        Dim TempBefore As String = Before(I).Split(":")(1)
        Dim TempAfter As String = After(I).Split(":")(1)
        If TempBefore <> TempAfter Then
            ReturnString += Before(I).Split(":")(0) + ":" + TempBefore + ">" + TempAfter + ","
        End If
    Next
    Return ReturnString.Substring(0, ReturnString.Length - 1)
End Function
于 2013-05-21T03:23:27.087 回答