Background:
I needed to split a string of numerous words into an array which separates the words for me for further use later on in my code. However, I needed to get rid of any numbers which might be present in the string so I declared a string contaning characters which I wanted to use as separators/delimiters as follows:
dim Separators As String = " 1234567890"
so my code became more or less as follows:
''//USING SPLIT-FUNCTION
dim MyTestString as String = "This is 9 a 567 test"
dim Separators As String = " 1234567890"
dim ResultWithNoNumbers() as String
ResultWithNoNumbers = Split(MyTestString,Separators.ToCharArray)
Messagebox.Show(ResultWithNoNumbers.Length.ToString)
''//Result is 1 and no split was performed
This did not work since the Split-functions did not consider my Separators as individual characters
however this worked..
''//USING SPLIT-METHOD
dim MyTestString as String = "This is 9 a 567 test"
dim Separators As String = " 1234567890"
dim ResultWithNoNumbers() as String
ResultWithNoNumbers = MyTestString.Split(Separators.ToCharArray,
_StringSplitOptions.RemoveEmptyEntries)
Messagebox.Show(ResultWithNoNumbers.Length.ToString)
''//Result is 4 and split was performed
So far, so good - since one has more options with the Split-method compared to the Split-function, I managed to resolve my problem.
Now to my question, let's say I only needed the standard space-character (" ") as a delimiter (and no need to get rid of numbers like in above example), then both ways would work. So which one would you use? Apart from various options available, are there any advantages using a particular one? Perhaps one is faster, less memory-hungry?
EDIT: I'm developing for Windows Mobile and that's why speed- and memory-issues get important.
Thank you.