הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Thursday, September 14, 2006 4:25 PM
How do I delete all instances of vbCrLf from a string?
Thanks in advance.
All replies (7)
Thursday, September 14, 2006 4:50 PM ✅Answered
vbcrlf = environment.newline...
Dim MyString As String = "This is a Test" & Environment.NewLine & " This is the second line!"
Dim MyNewString As String = MyString.Replace(Environment.NewLine, String.Empty)
Friday, September 15, 2006 12:03 AM ✅Answered
For reading lines from a text file try something along these lines:
Dim tfr As System.IO.StreamReader = My.Computer.FileSystem.OpenTextFileReader(My.Application.Info.DirectoryPath & "\backups.dat")
Dim TheFileLines As New List(Of String)
While Not tfr.EndOfStream
TheFileLines.Add(tfr.ReadLine())
End While
tfr.Close()
tfr.Dispose()
Friday, September 15, 2006 3:40 AM ✅Answered
I'm not sure how you splitting the items
* Dim crlf() As String = {vbCrLf}
Dim line As String() = strContents.Split(crlf, StringSplitOptions.None)*
I found that if I had a CRLF at the end of each line and did a split using VBCR but not stringsplitoption parameter that it would leave the lf character in the string array items. Chnaging to the above seemed to cure the problem.
You could also do a string replace with the character with a space prior to deleteing the white space. This you would use on the string array items.
Thursday, September 14, 2006 7:41 PM
Thanks for your help, but it didn't work. Perhaps I should explain in more detail:
A list of filenames is saved in a file, each seperated by a vbCrLf. I read this into an array:
Dim fileList As String = My.Computer.FileSystem.ReadAllText(My.Application.Info.DirectoryPath & "\backups.dat")
If fileList <> "" Then
Dim k
For k = 0 To fileList.Split(vbCrLf).Length - 1
Dim strFileName As String = fileList.Split(vbCrLf)(k)
Next
End If
Exit Sub
eh:
However, the array that it returned still had the vbCrLf characters in it. How do I remove them?
Friday, September 15, 2006 4:02 PM
YAY! Thanks DMan1! It worked!!!
Monday, March 9, 2015 8:20 AM
or... simply
replace(ProvideTheStringHere,vbCrLf,"")
Monday, March 9, 2015 9:52 AM
or... simply
replace(ProvideTheStringHere,vbCrLf,"")
You are answering a post that is more than 8 years old.
You suggestion won't work. Replace is a function - the return value has to be assigned to a variable.
Dim NewString As String = Replace(ProvideTheStringHere, vbCrLf, "")