在字符串中查找 & vbCrLf & - vb.net

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31054097/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:14:22  来源:igfitidea点击:

find & vbCrLf & within a string - vb.net

vb.net

提问by user3428422

In a string I have something like "First & vbCrLf & Name" - however, I want to take out the & vbCrLf & so it doesnt cause a line break.

在一个字符串中,我有类似“First & vbCrLf & Name”的东西——但是,我想去掉 & vbCrLf & 所以它不会导致换行。

I have done something like

我做过类似的事情

If theString.Contains("& vbCrLf &") Then
    ' and replace, could do this above of course, but I just want it to go into the IF
End If 

and

If theString.Contains("\n") Then
    ' and replace, could do this above of course, but I just want it to go into the IF
End If 

and even "\r\n"but to no avail.

甚至"\r\n"无济于事。

What am I missing?

我错过了什么?

采纳答案by Keith

If theString.Contains(vbCrLf) Then
    'Do something
End If

Alternatively...

或者...

theString = theString.Replace(vbCrLf, "")

回答by Jason Musgrove

Try:

尝试:

If theString.Contains(Environment.NewLine) Then
   ' Code goes here
End If

回答by Andrew Mortimer

Remove the vbCrLf from the string literal in Contains.

从包含的字符串文字中删除 vbCrLf。

testVal = testVal.Replace(vbCrLf, String.Empty).Replace("&", String.Empty)

回答by rheitzman

Metacharacters not supported by VB.Net for Strings - can be used with RegEx and probably a few other .Net functions.

VB.Net 不支持用于字符串的元字符 - 可以与 RegEx 和其他一些 .Net 函数一起使用。

In your OP I think you intended:

在您的 OP 中,我认为您打算:

If theString.Contains("& vbCrLf &") Then

to be

成为

If theString.Contains(vbCrLf) Then

You can test for and replace in one command:

您可以在一个命令中测试和替换:

    Dim s As String = vbCrLf
    MsgBox(s.Length)
    s = s.Replace(vbCrLf, "") 
    MsgBox(s.Length)