I need a function (or code) that will physically change the words in a text
string to make the first word be last, second word next to last, etc. but
maintain the same position of the letters in each word.
e.g.
Before: The dog ran
After: ran dog the
Is there such a thing?
Thanks!
Bob
Armin Zingler - 02 Oct 2007 16:26 GMT
> I need a function (or code) that will physically change the words in
> a text string to make the first word be last, second word next to
[quoted text clipped - 6 lines]
>
> Is there such a thing?
Dim s As String = "The dog ran"
Dim words As String() = s.Split(" "c)
Array.Reverse(words)
s = String.Join(" "c, words)
Armin
Miro - 02 Oct 2007 16:29 GMT
> I need a function (or code) that will physically change the words in a text
> string to make the first word be last, second word next to last, etc. but
[quoted text clipped - 9 lines]
>
> Bob
I would almost assume you would have to read the file char by char, and
add to an "arraylist" every time you hit a space.
Then in the end, fly thru the array list backwards and write it back.
Im a newbie though.
M.
rowe_newsgroups - 02 Oct 2007 16:43 GMT
On Oct 2, 11:07 am, BobAchgill <BobAchg...@discussions.microsoft.com>
wrote:
> I need a function (or code) that will physically change the words in a text
> string to make the first word be last, second word next to last, etc. but
[quoted text clipped - 9 lines]
>
> Bob
How about this:
/////////////////
Module Module1
Sub Main()
Dim text As String = "The dog ran after the car"
Dim words As String() = text.Split(" "c)
Dim newText As String = String.Empty
For i As Integer = words.Length - 1 To 0 Step -1
newText &= words(i) & " "
Next
Console.WriteLine(newText)
Console.Read()
End Sub
End Module
////////////////////
Thanks,
Seth Rowe
Mythran - 02 Oct 2007 16:51 GMT
> On Oct 2, 11:07 am, BobAchgill <BobAchg...@discussions.microsoft.com>
> wrote:
[quoted text clipped - 39 lines]
>
> Seth Rowe
I was going along this route too, trying to help out, then remembered that
you can use an Array and use the Reverse method :D
Mythran
rowe_newsgroups - 02 Oct 2007 17:51 GMT
> > On Oct 2, 11:07 am, BobAchgill <BobAchg...@discussions.microsoft.com>
> > wrote:
[quoted text clipped - 44 lines]
>
> Mythran
Yeah, curse me and my obsessive need to do everything the manual
way. :-)
Besides, this is the first time in about a year I had a need to use
the "Step" keyword :-)
Thanks,
Seth Rowe