Why line2does it replace only the alternating half of the entries?
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|", "|")
Result:
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|.."
I tried using RegEx, but getting similar results.
Is there a better way than this below?
Do While line1.Contains("|CCC|")
line1 = line1.Replace("|CCC|", "||")
Loop
source
share