473,490 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
Oct 2 '07 #1
5 3761
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
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

Oct 2 '07 #2
"BobAchgill" <Bo********@discussions.microsoft.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(words)
s = String.Join(" "c, words)
Armin

Oct 2 '07 #3
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.
Oct 2 '07 #4


"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:11*********************@g4g2000hsf.googlegrou ps.com...
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
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
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
Oct 2 '07 #5
On Oct 2, 11:51 am, "Mythran" <kip_pot...@hotmail.comwrote:
"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:11*********************@g4g2000hsf.googlegrou ps.com...
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
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

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

Oct 2 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
12717
by: Simon | last post by:
Hi, I have written a function to trim char *, but I have been told that my way could be dangerous and that I should use memmove(...) instead. but I am not sure why my code could be 'dangerous'...
26
13254
by: rkleiner | last post by:
Is there a regular expression to find the first unmatched right bracket in a string, if there is one? For example, "(1*(2+3))))".search(/regexp/) == 9 Thanks in advance.
4
44320
by: Agnes | last post by:
in .net , any left function ?? or I should use Microsoft.VisualBasic.Left(myString, 5) Thanks
7
200769
by: ReidarT | last post by:
How do I use left, mid and right in vb.net? regards reidarT
12
23865
by: patang | last post by:
This is really silly question. Dim s As String s = "the" s = Right(s, 2) Why this gives me compilation error? (This works in VB6 .. what do I have to do to make it work in VB.Net) I have...
9
58220
by: sql guy123 | last post by:
I normally use MS ACCESS vs MS SQL,, which has a left() and right() function. I need to use MS SQL for this project but I am not familiar with it. I have read a few books, but can not figure out...
2
2314
by: muler | last post by:
Hi all, This is an excerpt from the Book "Programming Microsoft Visual C#: The Language": A function evaluates to the return value. When a reference type is returned, a function is available...
6
6737
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have two questions with regards to the LEFT function. I ran into a problem with the LEFT function today. I knew it was a valid Function, but when I tried to use it, it was getting interpreted...
3
14830
by: Steve | last post by:
I use the instr function frequently to find particular characters within a string and manipulate them eg all characters to the left of a particular character. If I understand correctly, Instr...
52
7751
by: marc | last post by:
Hello, Is it possible to right pad with "0" (or other character != blank) ? for example : 1 , length 10 ="1000000000" I've tried with sprintf but I can only left pad with "0" or right pad with...
0
7112
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7146
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7183
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5448
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3074
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1389
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.