Right to Left string function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Qm9iQWNoZ2lsbA==?=

    Right to Left string function

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

    #2
    Re: Right to Left string function

    On Oct 2, 11:07 am, BobAchgill <BobAchg...@dis cussions.micros oft.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
    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.WriteLi ne(newText)

    Console.Read()
    End Sub

    End Module
    ////////////////////

    Thanks,

    Seth Rowe

    Comment

    • Armin Zingler

      #3
      Re: Right to Left string function

      "BobAchgill " <BobAchgill@dis cussions.micros oft.comschrieb
      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(w ords)
      s = String.Join(" "c, words)


      Armin

      Comment

      • Miro

        #4
        Re: Right to Left string function

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

        Comment

        • Mythran

          #5
          Re: Right to Left string function



          "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
          news:1191339824 .037192.77290@g 4g2000hsf.googl egroups.com...
          On Oct 2, 11:07 am, BobAchgill <BobAchg...@dis cussions.micros oft.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
          >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.WriteLi ne(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


          Comment

          • rowe_newsgroups

            #6
            Re: Right to Left string function

            On Oct 2, 11:51 am, "Mythran" <kip_pot...@hot mail.comwrote:
            "rowe_newsgroup s" <rowe_em...@yah oo.comwrote in message
            >
            news:1191339824 .037192.77290@g 4g2000hsf.googl egroups.com...
            >
            >
            >
            On Oct 2, 11:07 am, BobAchgill <BobAchg...@dis cussions.micros oft.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
            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.WriteLi ne(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
            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

            Comment

            Working...