Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

Right to Left string function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BobAchgill - 02 Oct 2007 16:07 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
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.