Right to Left string function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
BobAchgill said:
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?

Dim s As String = "The dog ran"
Dim words As String() = s.Split(" "c)
Array.Reverse(words)
s = String.Join(" "c, words)


Armin
 
BobAchgill said:
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

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.
 
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

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
 
rowe_newsgroups said:
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

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
 
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

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
 
Back
Top