vb.net 如何在 VB msgbox() 中使用 \n 换行...?

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

How to use \n new line in VB msgbox() ...?

vb.netnewlinemsgbox

提问by Wasim A.

What is the alternative to \n (for new line) in a VB.NETMsgBox()?

VB.NETMsgBox() 中\n(换行)的替代方法是什么?

回答by Fun Mun Pieng

  • for VB:vbCrLfor vbNewLine
  • for VB.NET:Environment.NewLineor vbCrLfor Constants.vbCrLf
  • 对于 VB:vbCrLfvbNewLine
  • 对于VB.NET:Environment.NewLinevbCrLfConstants.vbCrLf

Info on VB.NET new line: http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx

关于 VB.NET 新行的信息:http: //msdn.microsoft.com/en-us/library/system.environment.newline.aspx

The info for Environment.NewLinecame from Cody Grayand J Vermeire

信息Environment.NewLine来自Cody GrayJ Vermeire

回答by Pranay Rana

These are the character sequences to create a new line:

这些是用于创建新行的字符序列:

  • vbCris the carriage return (return to line beginning),

  • vbLfis the line feed (go to next line)

  • vbCrLfis the carriage return / line feed (similar to pressing Enter)

  • vbCr是回车(回到行首),

  • vbLf是换行符(转到下一行)

  • vbCrLf是回车/换行(类似于按回车)

I prefer vbNewLineas it is system independent(vbCrLfmay not be a true new line on some systems)

我喜欢vbNewLine,因为它是独立于系统的vbCrLf可能不是在某些系统上一个真正的新行)

回答by Developer

Try using vbcrlffor a newline

尝试使用vbcrlf换行符

msgbox "This is how" & vbcrlf & "to get a new line"

回答by Hans Olsson

Add a vbNewLineas:

添加一个vbNewLine

"text1" & vbNewLine & "text2"

回答by slagou

An alternative to Environment.NewLine is to use :

Environment.NewLine 的替代方法是使用:

Regex.Unescape("\n\tHello World\n")

from System.Text.RegularExpressions

来自 System.Text.RegularExpressions

This allows you to escape Text without Concatenating strings as you can in C#, C, java

这允许您在不连接字符串的情况下转义文本,就像在 C#、C、java 中一样

回答by user6225788

The correct format is :

正确的格式是:

"text1" + vbNewLine + "text2"

回答by SQAHero

Use the command "vbNewLine"

使用命令“vbNewLine”

Example

例子

Hello & vbNewLine & "World"

will show up as Hello on one line and World on another

将在一行中显示为 Hello,在另一行中显示为 World

回答by Martin Reicher

msgbox "This is the first line" & vbcrlf & "and this is the second line"

or in .NET msgbox "This is the first line" & Environment.NewLine & "and this is the second line"

或在 .NET 中 msgbox "This is the first line" & Environment.NewLine & "and this is the second line"

回答by user2885689

Module MyHelpers
    <Extension()>
    Public Function UnEscape(ByVal aString As String) As String

       Return Regex.Unescape(aString)

    End Function
End Module

Usage:

用法:

console.writeline("Ciao!\n".unEscape)