4

简单的编码分配:从文本框中获取文本并将其翻转,使其成为反语:

ie Hello My Name Is David 将是“divad si eman ym olleh”(程序不必匹配大小写,只需匹配字母)

这是我找到的,你还有其他方法吗?

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
4

8 回答 8

6

StrReverse您可以使用该函数(在 Microsoft.VisualBasic 中)在一行中完成。

Dim myText As String = "My Name is Dave"
Dim revText As String = StrReverse(myText)
于 2012-11-05T04:46:56.183 回答
2

快速一班轮。

lblOne.Text = String.Join("", "divad si eman ym olleh".Reverse())
于 2012-11-05T12:42:13.573 回答
1

Microsoft.VisualBasic

Dim myText As String = My Name is  abc
Dim revText As String = StrReverse(myText)

输出:“cba si eman ym”

于 2018-12-15T20:44:09.007 回答
0

反转字符串的最简单方法是:

Dim s As String = "1234ab cdefgh"
MessageBox.Show(s.AsEnumerable.Reverse.ToArray)
于 2014-07-29T07:20:46.323 回答
0

这是一种类似的方式,但行数更少。

Dim Original_Text As String = "Hello My Name is Ahmad"
Dim Reversed_Text As String = ""

For i = Original_Text.Length To 1 Step -1
    Reversed_Text &= Original_Text.Substring(i, 1)
Next
于 2012-11-05T04:45:57.440 回答
0

您可以使用String.Join而不是循环遍历每个字符并连接:

lblOne.Text = String.Join("", arr)
于 2012-11-05T04:22:22.717 回答
0

创建一个function接受字符串的 a 返回一个反转的字符串。

Function Reverse(ByVal value As String) As String
    Dim arr() As Char = value.ToCharArray()
    Array.Reverse(arr)
    Return New String(arr)
End Function

并尝试像这样使用它,

lblOne.Text  = Reverse(Textbox1.Text)
于 2012-11-05T04:24:18.783 回答
0
  1. First Create a textbox, it will be TextBox1
  2. then create a button and name it Reverse
  3. then Create a label, it will be Label1
  4. Now double click on Reverse Button (Go to Button Click Event)
  5. and type following code.
  6. and run software And type your string in textbox and click on reverse button.

    Dim MainText As String = TextBox1.Text
    Dim revText As String = StrReverse(MainText)
    Label1.Text = revText
    
于 2014-08-21T14:19:50.490 回答