here is my problem:
I have a sentence and I split it using Message.Text.Split(" ")
to get an array of words, however there is the possibility that some words are separated with '
instead of space (Ex. all'una
).
if this happens that array element will be all'una
instead of having to separated elements all
and una
. So what I did for get that result is:
'loop start (tried for, for each and while using words.GetEnumerator())
'do stuff here
If word.Contains("'") Then
Dim apos() As String = word.Split("'")
For Each subword As String In apos
words.Add(it)
Next
End If
'do other stuff here
'loop end
problems is that words array (or list) change it's size correctly, but the loop ignore new elements. I looked in Internet and read this:
Modifying the Collection. The enumerator object returned by GetEnumerator normally doesn't let you change the collection by adding, deleting, replacing, or reordering any elements. If you change the collection after you have initiated a For Each...Next loop, the enumerator object becomes invalid, and the next attempt to access an element causes an InvalidOperationException exception. However, this blocking of modification isn't determined by Visual Basic, but rather by the implementation of the IEnumerable interface. It is possible to implement IEnumerable in a way that allows for modification during iteration. If you are considering doing such dynamic modification, make sure that you understand the characteristics of the IEnumerable implementation on the collection you are using.
Is this the only solution I have?