vb.net字符串段落中的新行

时间:2015-06-01 07:51:31

标签: vb.net string

我打算在一个段落中断行。

是否有\n打破字符串中的行?

Dim info As String = "Page name \n Date and Time" & DateTime.Now.ToString("yyyy-MM-dd, HH:mm:ss") & "\n Printed By Admin"

2 个答案:

答案 0 :(得分:2)

使用Environment.NewLine

Dim info As String = "Page name " & Environment.NewLine _
                     & " Date and Time" _
                     & DateTime.Now.ToString("yyyy-MM-dd, HH:mm:ss") _
                     & Environment.NewLine & " Printed By Admin"

XML literalsEmbed Expressions

Dim info As String = <info>
Page name
Date and Time <%= DateTime.Now.ToString("yyyy-MM-dd, HH:mm:ss") %> 
Printed By Admin
</info>.Value

或者,如果您在循环中创建字符串,则可以使用StringBuilder

Dim info As New StringBuilder()
info.AppendLine("Page name")
info.Append("Date and Time ")
info.AppendLine(DateTime.Now.ToString("yyyy-MM-dd, HH:mm:ss"))
info.AppendLine("Printed By Admin")

方法.AppendLine("text")会在给定字符串的末尾添加Environment.NewLine

答案 1 :(得分:1)

使用 vbLf

Dim info As String = "Page name " & vbLf & " Date and Time" & DateTime.Now.ToString("yyyy-MM-dd, HH:mm:ss") & "" & vbLf & " Printed By Admin"