string VB.Net 中的换行符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/515722/
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
New line character in VB.Net?
提问by Vinod
I am trying to print a message on a web page in vb.net. I am trying to get the messages in new lines. I tried using the "\r\n" and the new line character. But this is getting printed in the page instead of it comming to the next line. Please let me know if there is any alternative.
我正在尝试在 vb.net 的网页上打印一条消息。我试图在新行中获取消息。我尝试使用 "\r\n" 和换行符。但这会打印在页面中,而不是进入下一行。请让我知道是否有其他选择。
采纳答案by andynormancx
You need to use HTML on a web page to get line breaks. For example "<br/>" will give you a line break.
您需要在网页上使用 HTML 来获取换行符。例如“<br/>”会给你一个换行符。
回答by Anton Gogolev
Check out Environment.NewLine
. As for web pages, break lines with <br>
or <p></p>
tags.
退房Environment.NewLine
。对于网页,用<br>
或<p></p>
标签换行。
回答by Garry Shutler
Environment.NewLine
is the most ".NET" way of getting the character, it will also emit a carriage return and line feed on Windows and just a carriage return in Unix if this is a concern for you.
Environment.NewLine
是获取字符的最“.NET”方式,它还会在 Windows 上发出回车和换行,如果您担心的话,在 Unix 中只会发出回车。
However, you can also use the VB6 style vbCrLf
or vbCr
, giving a carriage return and line feed or just a carriage return respectively.
回答by JaredPar
The proper way to do this in VB is to use on of the VB constants for newlines. The main three are
在 VB 中执行此操作的正确方法是使用 VB 常量作为换行符。主要的三个是
- vbCrLf = "\r\n"
- vbCr = "\r"
- vbLf = "\n"
- vbCrLf = "\r\n"
- vbCr = "\r"
- vbLf = "\n"
VB by default doesn't allow for any character escape codes in strings which is different than languages like C# and C++ which do. One of the reasons for doing this is ease of use when dealing with file paths.
默认情况下,VB 不允许在字符串中使用任何字符转义码,这与 C# 和 C++ 等语言不同。这样做的原因之一是在处理文件路径时易于使用。
- C++ file path string: "c:\\foo\\bar.txt"
- VB file path string: "c:\foo\bar.txt"
- C# file path string: C++ way or @"c:\foo\bar.txt"
- C++ 文件路径字符串:“c:\\foo\\bar.txt”
- VB文件路径字符串:“c:\foo\bar.txt”
- C#文件路径字符串:C++方式或@"c:\foo\bar.txt"
回答by Sachin Chavan
If you are using something like this.
如果你正在使用这样的东西。
Response.Write("Hello \r\n")
Response.Write("World \r\n")
and the output is
输出是
Hello\r\nWorld\r\n
Then you are basically looking for something like this
那么你基本上是在寻找这样的东西
Response.Write("Hello <br/>")
Response.Write("World <br/>")
This will output
这将输出
Hello
World
you can also just define "<br />" as constant and reuse it
您也可以将“<br />”定义为常量并重用它
eg.
例如。
Public Const HtmlNewLine as string ="<br />"
Response.Write("Hello " & HtmlNewLine)
Response.Write("World " & HtmlNewLine)
回答by Omar Abid
it's :
它的 :
vbnewline
vbnewline
for example
例如
Msgbox ("Fst line" & vbnewline & "second line")
Msgbox ("Fst line" & vbnewline & "second line")
回答by Gerrie Schenck
回答by Chris Van Opstal
回答by Nordanne Isahac
you can solve that problem in visual basic .net without concatenating your text, you can use this as a return type of your overloaded Tostring:
您可以在 Visual Basic .net 中解决该问题,而无需连接文本,您可以将其用作重载 Tostring 的返回类型:
System.Text.RegularExpressions.Regex.Unescape(String.format("FirstName:{0} \r\n LastName: {1}", "Nordanne", "Isahac"))
回答by sahdeo
In asp.net for giving new line character in string you should use <br>
.
在 asp.net 中用于在字符串中提供换行符,您应该使用<br>
.
For window base application Environment.NewLine
will work fine.
对于基于窗口的应用程序Environment.NewLine
将正常工作。