比较不同值的字符串

Compare strings for different values

我有 2 个字符串:

字符串 1: @serial1@code1@true@serial2@code2@false@serial3@code3@true

字符串 2: @serial1@code1@false@serial2@code2@false@serial3@code3@false

我需要的是更改组的信息(serial1,code1,true/false)。就像上面的例子一样,我只想要 (serial1,code1,t/f) 和 (serial3,code3,t/f)

的数据

STRING1 在 page_load 上加载,STRING2 将在单击保存按钮后加载。所以我只想访问数据库,而不是所有值都更改的那些值。

请提出一些合适的逻辑。

提前致谢。

您可以使用 String.Split() 将您的字符串转换为字符串数组,然后计算数组项。

示例: strOriginal() = string1.Split("@") strChanged() = string2.Split("@")

' Assuming both strings had the same number of elements...
For i as Integer = 0 to strOriginal.Length - 1
    If strOriginal(i) <> strChanged(i) Then
        ' Your DB write logic here...
    End If
Next