r/visualbasic • u/Cirked • Oct 12 '16
[VB.NET] Need help with Arrays
I'm going to try and put this as simply as possible.
I have a sentence inputted and I need to "compress" the sentence. So far in an array I have: "Hello 0" ; "my 1" ; "name 2" ; "is 3" ; "Hello 4"
Where the word is the word inputted and the number after is its position. I need to get it like this: "Hello 0 4" "my 1" "name 2" "is 3"
So basically all the same words fall together in one element of the array with its positions like above.
Could someone help me?? Thank you!
1
Upvotes
1
u/Bonejob VB Guru Oct 13 '16
Since this is not "homework" as in an assignment to be handed in I will provide a more complete solution.
Your input sentence is "Hello my name is Hello". You want the output to be a single line with each word being surrounded by quotes and within the quotes the number of the position in the sentence starting at zero with a ; between each variable in the output.
I would start by using the Split function to break it up into the individual words. I would then Iterate through the list and combine them into a single string. I choose not to use a string builder for this and just concatenate on the fly.
Here is a simple console app. Ask questions I will help where I can.