使用 vb.net 从字符串中删除回车
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28046903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove carriage return from string using vb.net
提问by PriceCheaperton
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
dotnetfiddle: https://dotnetfiddle.net/4FMxKD
I would like the string to look like "your string testing"
我希望字符串看起来像 "your string testing"
回答by Andrew Morton
Note that vbCrLf is equivalent to Chr(13) & Chr(10).
请注意,vbCrLf 等效于 Chr(13) 和 Chr(10)。
Also, as Plutonix pointed out, you are applying .Replaceto the string "testing". And you want to replace it with a space, according to your desired output.
此外,正如 Plutonix 所指出的,您正在申请.Replace字符串“testing”。并且您想根据所需的输出用空格替换它。
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)).
最后,以上假设您的意思是要替换整个 CRLF 序列而不仅仅是回车符 (Chr(13))。

