Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flip letters of a string - Visual Basic

Tags:

vb.net

Simple coding assignment: Take text from a textbox and flip it so it's backwords:

i.e. Hello My Name Is David would be "divad si eman ym olleh" ( The program doesn't have to match case, just the letters)

This is something I found, do you have any other methods?

Dim str As String = Textbox1.Text
Dim arr As New List(Of Char)
arr.AddRange(str.ToCharArray)
arr.Reverse()

For Each l As Char In arr
lblOne.Text &= l
Next
like image 757
Ds.109 Avatar asked Jan 16 '23 03:01

Ds.109


2 Answers

You can do it in one line with using the StrReverse function (in Microsoft.VisualBasic).

Dim myText As String = "My Name is Dave"
Dim revText As String = StrReverse(myText)
like image 53
sj1900 Avatar answered Feb 20 '23 20:02

sj1900


Quick one liner.

lblOne.Text = String.Join("", "divad si eman ym olleh".Reverse())
like image 32
Ceres Avatar answered Feb 20 '23 20:02

Ceres