检查文本框中的文本值是否为Newline

时间:2014-04-23 08:00:11

标签: vb.net char newline multiline

我有一个带有多行属性的文本框。验证文本框时,它将通过一个函数来检查每个字符的值是否在我允许的范围内。我有一些值有下线的新行:

" Sorabee让您的肌肤持久保湿!

描述

Sorabee护肤系列让您的肌肤保持水分"

这是3个句子,有3个换行符。如何在我的检查中插入此换行符,如下所示:

Public Function AllowedChar(ByVal str As String) As Integer
    Dim cnt As Integer
    Dim allowChars As Char() = "1234567890QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm!+=-/., ?".ToCharArray()
    Try
        cnt = 0
        For Each ch As Char In str ' to check whether special character exist in a string
            If Array.IndexOf(allowChars, ch) = -1 Then
                cnt = cnt + 1
            End If
        Next
        Return cnt
    Catch ex As Exception
        strErrMsg = "Oops! Something is wrong with verify special characters at AllowedChar"
        MessageBox.Show(strErrMsg & vbCrLf & "Err: " & ex.Message)
    End Try
End Function

我可以放一个空间来验证。但是如何将换行符作为allowChars?

1 个答案:

答案 0 :(得分:1)

对于Visual Basic中Windows控制台应用程序中的换行符,请尝试以下操作:

Console.WriteLine("hello", vbLf)

vbLf制作了一个所谓的“换行符”。

相关问题