输入一串字符,将字符串颠倒输出
解决时间 2021-05-09 21:49
- 提问者网友:夢醒日落
- 2021-05-09 17:06
最佳答案
- 五星知识达人网友:傲气稳了全场
- 2021-05-09 17:33
代码:
'
Dim Str as String
Private Sub Form_Click()
Text1 = ""
Text2 = ""
End Sub
Private Sub Command1_Click()
Str = Text1
Text2 = StrReverse(Str)
End Sub
全部回答
- 1楼网友:轮獄道
- 2021-05-09 18:10
Module Module1
Sub Main()
Console.WriteLine("请输入一个字符串:")
Dim s = Console.ReadLine
Console.WriteLine("逆序输出:")
For i As Integer = 1 To s.Length
Console.Write(Mid(s, s.Length - i + 1, 1))
Next
End Sub
End Module
上面这个代码是控制台下的,如果你写的是form程序,用这个过程就行,不过你要先拉一个Button1和TextBox1到窗体上:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s = TextBox1.Text
For i As Integer = 1 To s.Length / 2
Dim t = Mid(s, i, 1)
Mid(s, i, 1) = Mid(s, s.Length - i + 1, 1)
Mid(s, s.Length - i + 1, 1) = t
Next
TextBox1.Text = s
End Sub
- 2楼网友:不如潦草
- 2021-05-09 17:43
不用MID即可
For i = Len(sstr) - 1 To 0 Step -1 '该循环把选中的字符串反序存放在dstr变量中
dstr = dstr + sstr.Substring(i, 1)
Next i
我要举报
大家都在看
推荐资讯