为什么line2
只替换交替出现的一半?
Dim line1 As String = "AAA|BBB|CCC|CCC|CCC|CCC|EEE|FFF"
Dim line2 As String = "AAA|BBB|CCC|CCC|CCC|CCC|EEE|FFF"
Dim line3 As String = "AAA|BBB|CCC|CCC|CCC|CCC|EEE|FFF"
line1 = line1.Replace("CCC", "")
line2 = line2.Replace("|CCC|", "||")
line3 = line3.Replace("CCC|", "|")
结果:
line1 = "AAA|BBB|||||EEE|FFF" -- OK, but fails when element is "..|ZZZCCCZZZ|.."
line2 = "AAA|BBB||CCC||CCC|EEE|FFF" -- Not OK
line3 = "AAA|BBB|||||EEE|FFF" -- OK, but fails similar to Line1 edge-case for "..|ZZZCCC|.."
我曾尝试使用 RegEx,但得到了类似的结果。
下面真的没有比这更好的方法了吗?
Do While line1.Contains("|CCC|")
line1 = line1.Replace("|CCC|", "||")
Loop