-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 に答える