splitting a sentence into word per word in array with a twist...  
Author Message
sokelut





PostPosted: Visual Basic Express Edition, splitting a sentence into word per word in array with a twist... Top

Hi everyone this is my first post. I'm fairly new to programming. I can't find answer to my problem from the book I purchased on mastering VB express edition
so I thought I'd ask here.

and I have this;

dim array() as string
array(0) = "human hair found everywhere"
array(1) = " I really love pringles"

'I can do this on the first element
dim wordSplit() as string = split(array(0), " ")

msgbox(wordSplit(1)) 'this would display "hair"

msgbox(wordSplit(2)) 'this would display "found"

'the next is where the problem occurs
'how can I do the same thing to the second element
'I tried these but they won't work
' dim wordSplit() as string = split(array(1), " ") <--- gives nothing
' dim wordSplit() as string = split(array(1), " ") <--- gives nothing
' dim wordSplit() as string = split(array(1), "") <--- gives " I really love pringles"
' dim wordSplit() as string = split(array(0), vbTab) <--- gives " I really love pringles"

so now I'm not really sure if this is doable or not. I hope someone can help me with this thank you.



Visual Studio Express Editions12  
 
 
Andrej Tozon





PostPosted: Visual Basic Express Edition, splitting a sentence into word per word in array with a twist... Top

Hi,

try splitting the string by specifying RemoveEmptyEntries as StringSplitOption:

Dim wordSplit() As String = array(1).Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)

Hope this helps,

Andrej



 
 
jwooley





PostPosted: Visual Basic Express Edition, splitting a sentence into word per word in array with a twist... Top

I don't know if it meets your needs or not, but you could consider a RegularExpression.Matches collection with the following RegEx: "[a-zA-Z]*" This would give you any groupings of alpha characters, but exclude anything that is not a number.

Jim Wooley
http://devauthority.com/blogs/jwooley



 
 
sokelut





PostPosted: Visual Basic Express Edition, splitting a sentence into word per word in array with a twist... Top

thanks andrej that's exactly what I'm looking for

and it worked!


 
 
ahmedilyas





PostPosted: Visual Basic Express Edition, splitting a sentence into word per word in array with a twist... Top

you could but that would be overkill as regex is expensive and should only be used when neccessary and for regular pattern searching throughout the application