Reputation: 1779
I have some strings (file paths) that sometimes have randomly placed line breaks (CRLF) inside of them that I have to remove. How would I go about doing that?
Upvotes: 5
Views: 19532
Reputation: 5694
Have a look at the Replace(..)
function.
someVariable = Replace(someVariable, vbNewLine, "")
Upvotes: 13
Reputation: 13820
This will remove all CRLFs in your string.
strFileName = Replace(strFileName, vbNewLine, "")
Here is a function you can put in a helper module:
Public Function CleanFilePath(FilePath As String) As String
Return Replace(FilePath, vbNewLine, "")
End Function
EDIT:
Alternatively, here is a helper subroutine to modify the string itself. This is not standard practice in newer languages, though.
Public Sub CleanFilePath(ByRef FilePath As String)
FilePath = Replace(FilePath, vbNewLine, "")
End Sub
Upvotes: 3