vb.net 如何使用多个分隔符拆分字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14922957/
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-17 12:22:18 来源:igfitidea点击:
How to split a string by using more than one delimiter
提问by Dinesh
Below a script I used in my SSIS package.
下面是我在 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
This script only succeeds when having a tab as delimiter. But I need both tab and non tab characters as delimiters.
此脚本仅在使用制表符作为分隔符时成功。但我需要制表符和非制表符作为分隔符。
回答by Olivier Jacot-Descombes
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.
通过使用字符文字后缀C。

