English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Im trying to make a program that turns text backwards, for example:
Normal: Hello welcome to Yahoo!
Changed: olleh emoclew ot !oohay

Can this be done in Visual Basic.Net?
If so please give code or link and not to pscode.com.

Notice that it changes the single word backwords and not the whole piece of text.

2007-02-28 09:01:55 · 4 answers · asked by sbraidley 3 in Computers & Internet Programming & Design

I need it also to work via two textbox control's one called textbox1 and textbox2 so could any one set this up for me as I want the user to input text into textbo1 and when they press button1 then textbox2 shows the converted text.

2007-02-28 09:22:22 · update #1

4 answers

Dim strIn As String
Dim strTmp() As String
Dim strOut As String = ""
Dim strWord As String
Dim strRevWord As String = ""
Dim i As Integer


strIn = "Hello welcome to Yahoo!"
strTmp = Split(strIn, " ")

For Each strWord In strTmp
For i = strWord.Length - 1 To 0 Step -1
strRevWord = strRevWord & strWord.Substring(i, 1)
Next
strOut = strOut & strRevWord & Chr(32)
strRevWord = ""
Next

MsgBox(strOut)

2007-02-28 09:13:04 · answer #1 · answered by Zlavzilla 3 · 2 1

This probably is neither the easiest nor most efficient way...i just thought it up right now:


dim origString,newString as String
origString = "Welcome to Yahoo!"
Dim word() as string
Dim wordcount as integer = 1

for x as integer = 1 to len(origString)
if mid(origString,x,1) = " " then
wordcount = wordcount + 1
ReDim Preserve word(wordcount)
else
word(wordcount) = word(wordcount) + mid(origString,x,1)
end if
next

dim newWord(wordcount)
for x as integer = 1 to wordcount
for y as integer = len(word(x)) to 1 step -1
newWord(x) = newWord(x) & mid(word(x),y,1)
next

if len(newString) > 1 then newString = newString & " "
next x

2007-02-28 17:17:09 · answer #2 · answered by Scotty Doesnt Know 7 · 0 1

here it is:

--------------------------------------------------------------
Public Function ReverseWords(s As String) As String

Dim temp As Variant
Dim result As String

' split the strings into tokens
temp = Split(s)

' iterate over the array of string
For i = 0 To UBound(temp)

' reverse each word
temp(i) = StrReverse(temp(i))

Next


' join the reversed words into a new string as result
ReverseWords = Join(temp)


End Function


' test it

Public Sub test()

Debug.Print ReverseWords("Hello welcome to Yahoo!")

End Sub
--------------------------------------------------------------


Have Fun
M.

2007-02-28 17:21:27 · answer #3 · answered by Martin G. 4 · 1 0

load the text into an array and look for ASCII 20H (space) Then reverse anything up to the next 20H

2007-02-28 17:12:27 · answer #4 · answered by Del Piero 10 7 · 0 3

fedest.com, questions and answers