Hi, I am making a CSV class for reading and updating CSV file. Anyway I use a little split function I found ages ago, It works well splits string with comma's , and can also split strings with quotes. The problem it uses RegularExpressions to be honest I not that good with RegularExpressions, Anyway what I want is to have my string function split on anything say split a string like.
Ben;Jones
or
Ben|Jones
I left my function below so you guys can have a look and maybe help me fix to what I want to do Thanks.
How to use function.
Ben;Jones
or
Ben|Jones
I left my function below so you guys can have a look and maybe help me fix to what I want to do Thanks.
Code:
Private Function SplitString(ByVal Source As String) As String()
Dim Tmp(0) As String
Const VBQuote As String = """"
Dim Patten As String = ",(?=(?:[^\" + VBQuote + "]*\" + VBQuote +
"[^\" + VBQuote + "]*\" + VBQuote + ")*(?![^\" + VBQuote + "]*\" + VBQuote + "))"
If String.IsNullOrEmpty(Source) Then
SplitString = Tmp
Else
'Split the string and return as array.
SplitString = System.Text.RegularExpressions.Regex.Split(Source, Patten)
End If
End Function
Code:
Dim sText() As String = SplitString("Ben,Jones")
'Example
MsgBox(sText(0)) 'Ret Ben
MsgBox(sText(1)) 'Ret Jones