473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to reverse string using loop

3 2Bits
Hai, i got a problem with reverse text using loop, i have try like this


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim reverse_text As String
reverse_text = TextBox1.Text
For i As Integer = reverse_text .Length To 1 Step -1
TextBox2.Text &= Mid(reverse_text , i, 1)
Next

End Sub

The Result is
EAT APPLE reverse to ELPPA TAE

But that not the reverse result i want,

How can i do to make the result look like this,

EAT APPLE reverse to TAE ELPPA


Pls, Help, Thanks Before
Nov 3 '21 #1

✓ answered by cactusdata

This is one method:
Expand|Select|Wrap|Line Numbers
  1. Dim plain_text As String
  2. Dim reverse_text As String
  3.  
  4. Dim separator As Char
  5. Dim words() As String
  6. Dim item As Integer
  7. Dim chars() As Char
  8.  
  9. plain_text = "EAT APPLE"
  10. separator = " "
  11.  
  12. words = plain_text.Split(separator)
  13. For    item = 0 To words.Length - 1
  14.     chars = words(item).ToCharArray()    
  15.     Array.Reverse(chars)
  16.     words(item) = New String(chars)
  17. Next
  18. reverse_text = String.Join(separator, words)
  19.  
  20. Console.WriteLine(plain_text)
  21. Console.WriteLine(reverse_text)
Output:
Expand|Select|Wrap|Line Numbers
  1. EAT APPLE
  2. TAE ELPPA

6 14220
cactusdata
214 Expert 128KB
Split into an array of words, reverse each item, join the words with a space.
Nov 3 '21 #2
sugianoor
3 2Bits
But how can i do that ? Im really new with vb.net
Nov 4 '21 #3
SioSio
272 256MB
What is the reason for using loop?
Expand|Select|Wrap|Line Numbers
  1. TextBox2.Text = StrReverse(reverse_text)
Nov 4 '21 #4
cactusdata
214 Expert 128KB
This is one method:
Expand|Select|Wrap|Line Numbers
  1. Dim plain_text As String
  2. Dim reverse_text As String
  3.  
  4. Dim separator As Char
  5. Dim words() As String
  6. Dim item As Integer
  7. Dim chars() As Char
  8.  
  9. plain_text = "EAT APPLE"
  10. separator = " "
  11.  
  12. words = plain_text.Split(separator)
  13. For    item = 0 To words.Length - 1
  14.     chars = words(item).ToCharArray()    
  15.     Array.Reverse(chars)
  16.     words(item) = New String(chars)
  17. Next
  18. reverse_text = String.Join(separator, words)
  19.  
  20. Console.WriteLine(plain_text)
  21. Console.WriteLine(reverse_text)
Output:
Expand|Select|Wrap|Line Numbers
  1. EAT APPLE
  2. TAE ELPPA
Nov 4 '21 #5
sugianoor
3 2Bits
Thank You Very Much, You're The Best 👍
Nov 4 '21 #6
SioSio
272 256MB
I understand what you want to do.
Expand|Select|Wrap|Line Numbers
  1.         Dim i As integer
  2.         textBox2.Text = ""
  3.         Dim arr1() As String = System.Text.RegularExpressions.Regex.Split(textBox1.text, "\s")
  4.         For i = 0 to UBound(arr1) - 1
  5.             textBox2.text = textBox2.text & StrReverse(arr1(i)) & " "
  6.         Next i
  7.         textBox2.text = textBox2.text & StrReverse(arr1(i))
Nov 18 '21 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
1
by: Jerry | last post by:
Hi, I want to draw a reverse string, does anyone know how to implement it? And I want to draw a vertical string, it can be implemented by setting StringFormat.StringFormatFlags...
3
by: minguskhan | last post by:
Does anyone know how to reverse a string using a loop?
3
by: nico3334 | last post by:
I'm filling in a Report with SQL data using VB code. I'm using LOOP and MoveNext. Before using MoveNext, I would like to be able to check whether the new data is equal to the previous data that was...
1
by: python101 | last post by:
I would like to use loop 'for' to make something look like ------ * * * * * * * * * * #(please don't mind ----- because I can not type the first star in right position) however I...
5
by: boss1 | last post by:
hi all, i have a problem with loop in select statement.i m using code : <select name = "s" size = "1" > <option selected>P-Code</option> <option...
2
by: monkey0525 | last post by:
Hi, I'm writing a program that reverses the lines of a String using the LinkedList structure, which includes an iterator. I have my code written out, but every time my program runs, it takes a very...
5
by: sandeep n | last post by:
I am not getting reverse string using following code, can u explain where i did mistake and correct it with regards sandeep code-->>> #include<stdio.h>
1
by: Newbie318 | last post by:
#include <iostream> #include <string> using namespace std; bool isVowel(char); int main () { // Declare variables.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.