I could have sworn I have stripped CRLF in the past but not sure why the following isn't working:
myString = "ABC" & vbCrLf & "DEF"
str1 = Replace(myString, vbLf, "")
str2 = Replace(str1, vbCrLf, "")
str3 = Replace(str2, vbNewLine, "")
MsgBox str3
The code above doesn't work the result is:
ABC
DEF
myString = "ABC" & vbCrLf & "DEF"
str1 = Replace(myString, Chr(13), "")
str2 = Replace(str1, Chr(10), "")
MsgBox str2
The code above does work the result is:
ABCDEF
Solution: Thanks @ Mat for the answer (The problem on the first code was the order I was trying to remove the items) VbCrLf & VbNewLine is the same and trying to remove the combo vbCr+VbLf after removing VbLf won't work
The premise is flawed:
The string is made of "ABC",
vbCrLf
, and "DEF".vbCrLf
isvbCr
andvbLf
, which on any Windows box isvbNewLine
.When you do:
You replace
vbLf
and leave thevbCr
character in place.Then you replace
vbCrLf
butvbLf
is already gone sovbCrLf
isn't in the string.Then you replace
vbNewLine
which is basically doing the exact same thing as the previous instruction, and the result is a string that's been stripped ofvbLf
but still containsvbCr
.This code works as expected:
As does this:
Or this:
Or even this:
Your second snippet works as intended, because you do remove both
vbCr
(Chr(13)
) andvbLf
(Chr(10)
) characters. Simple as that.