如何使用多个分隔符拆分字符串

时间:2013-02-17 15:56:15

标签: vb.net

在我的SSIS包中使用的脚本下面。

If (Row.AnswerType.Trim().ToUpper = "MULTIPLE SELECT" And _
    Row.SurveyQuestionID = Row.SurveyDefinitionDetailQuestionNumber) Then

    Dim Question1 As String = Row.SurveyDefinitionDetailAnswerChoices.ToUpper.Trim()
    Dim ans1 As String = Row.SurveyAnswer.ToUpper.Trim()

    For Each x As String In ans1.Split(New [Char]() {CChar(vbTab)})
        If Question1.Contains(x) Then
            Row.IsSkipped = False
        Else
            Row.IsSkipped = True
            'Row.IsAllowed = True
            Row.ErrorDesc = "Invalid Value in Answer Column For Multiple Select!"
        End If
    Next
End If

只有将制表符作为分隔符时,此脚本才会成功。但我需要制表符和非制表符作为分隔符。

1 个答案:

答案 0 :(得分:7)

将所有需要的字符添加到字符数组

ans1.Split(New [Char]() { CChar(vbTab), CChar(" "), CChar(";") })

或者

ans1.Split(New [Char]() { CChar(vbTab), " "C, ";"C })

使用字符文字后缀C