MatsT
MatsT

Reputation: 1779

Remove character from string in VB6

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

Answers (3)

Kevin
Kevin

Reputation: 5694

Have a look at the Replace(..) function.

someVariable = Replace(someVariable, vbNewLine, "")

Upvotes: 13

Devin Burke
Devin Burke

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

Alex K.
Alex K.

Reputation: 175766

Replace$() replaces;

path = Replace$(path, vbcrlf, "")

Upvotes: 6

Related Questions