J
JV
Well, here's some VB as an example. They have a string which is doubly
delimited. In other words, each token in the string is itself another
delimited string.
Public Function ExampleFunction(ByVal stringToSplit As String, _
Optional ByVal innerDelimiter As String = "~", _
Optional ByVal outerDelimiter As String = "#~#")
Dim bigArray() As String
Dim smallArray() As String
bigArray = stringToSplit.Split(outerDelimiter)
' (etc.)
Now, to translate that to C# you would need a String.Split() function which
accepts a String for delimiter parameter and treats the entire string as the
delimiter, not a list of delimiter characters. It's a function that
probably makes sense to have in the framework string class (along with a few
others that I always thought they should had added). To accomplish this,
you would have to do one of the following:
1) Use Regex.Split() -- probably the best choice, but a bit ugly
2) Use Microsoft.VisualBasic.Strings.Split() -- requires linking to the VB
library, but is an easy solution
3) Roll your own Split() function and pass it the string you want to split
(not very object-oriented, unfortunately, but workable)
delimited. In other words, each token in the string is itself another
delimited string.
Public Function ExampleFunction(ByVal stringToSplit As String, _
Optional ByVal innerDelimiter As String = "~", _
Optional ByVal outerDelimiter As String = "#~#")
Dim bigArray() As String
Dim smallArray() As String
bigArray = stringToSplit.Split(outerDelimiter)
' (etc.)
Now, to translate that to C# you would need a String.Split() function which
accepts a String for delimiter parameter and treats the entire string as the
delimiter, not a list of delimiter characters. It's a function that
probably makes sense to have in the framework string class (along with a few
others that I always thought they should had added). To accomplish this,
you would have to do one of the following:
1) Use Regex.Split() -- probably the best choice, but a bit ugly
2) Use Microsoft.VisualBasic.Strings.Split() -- requires linking to the VB
library, but is an easy solution
3) Roll your own Split() function and pass it the string you want to split
(not very object-oriented, unfortunately, but workable)