2

My code doesn't remove the carriage return from the string:

Imports System
Imports Microsoft.VisualBasic

Public Module Module1

    Public Sub Main()
        Console.WriteLine("Hello World")
        Dim s As String = "your string" + Chr(10) & Chr(13) + "testing".Replace(vbCrLf, "")
        Console.WriteLine(s)
    End Sub
End Module

dotnetfiddle: https://dotnetfiddle.net/4FMxKD

I would like the string to look like "your string testing"

2
  • 1
    CR=Chr(13). LF=Chr(10). You have them the wrong way round ;) Commented Jan 20, 2015 at 13:49
  • there is no VBCrLf in "testing"; you are trying to replace it where it does not exist; and you will want to replace it with a space since there is not one between "string" and "testing" Commented Jan 20, 2015 at 13:54

1 Answer 1

7

Note that vbCrLf is equivalent to Chr(13) & Chr(10).

Also, as Plutonix pointed out, you are applying .Replace to the string "testing". And you want to replace it with a space, according to your desired output.

So what you should have is

Dim s As String = ("your string" & Chr(13) & Chr(10) & "testing").Replace(vbCrLf, " ")

Finally, the above assumes that you meant that you want to replace the entire CRLF sequence rather than just the carriage return (Chr(13)).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.