Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

vb.net - How to split a string by using more than one delimiter

Below a script I used in my SSIS package.

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

This script only succeeds when having a tab as delimiter. But I need both tab and non tab characters as delimiters.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add all the needed characters to the character array

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

Or

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

by using the character literal suffix C.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...