vb.net字符串反转 C#字符串反转
gb2312>unicode>utf8, 以及逆转的方法'>VB.net 字符转换问题 字符(汉字、数字、字母、符号)>gb2312>unicode>utf8, 以及逆转的方法
字符编码转换吗?
成都创新互联长期为近1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为关岭企业提供专业的网站设计、做网站,关岭网站改版等技术服务。拥有10年丰富建站经验和众多成功案例,为您定制开发。
1.字符与gb2312(gbk的子集):
Public Function GBKEncode(ByVal sInput As String) As String
Dim ret_GBKEncode As String = ""
Dim i As Integer
Dim startIndex As Integer = 0
Dim endIndex As Integer
Dim x() As Byte = System.Text.Encoding.Default.GetBytes(sInput) '字符以及字符串在vb2008中都是以unicode编码存储的
endIndex = x.Length - 1
For i = startIndex To endIndex
ret_GBKEncode = "%" Hex(x(i))
Next
Return ret_GBKEncode
End Function
'GBK解码
Public Function GBKDecode(ByVal sInput As String) As String
sInput = sInput.Replace("%", "")
Dim ret_GBKDecode As String = ""
Dim sLen As Integer = sInput.Length
Dim n As Integer = sLen \ 2
Dim sBytes(0 To n - 1) As Byte
'转化为字节码
For i As Integer = 1 To n
sBytes(i - 1) = CByte("H" sInput.Substring(2 * i - 2, 2))
Next
'将字节码转化为字符串
ret_GBKDecode = System.Text.Encoding.Default.GetString(sBytes)
Return ret_GBKDecode
End Function
2.Unicode字符串为UTF-8
Imports System.Text
Public Function StringAsUtf8Bytes(ByVal strData As String) As Byte()
Dim bytes() As Byte
bytes = Encoding.UTF8.GetBytes(strData)
Return bytes
End Function
'这里可以类推出好几种。
vb中将字符串反转的代码是什么?
代码如下,你在Text1中输入原字符串后按Command1按钮Text2中就出现与原字符串逆序的字符串:
Dim Str as String
Private Sub Form_Click()
Text1 = ""
Text2 = ""
End Sub
Private Sub Command1_Click()
Str = Text1
Text2 = StrReverse(Str)
End Sub
用VB6.0写字符串反转的程序
REM 这是VB.NET写的函数 VB6应该也是一样的
Function StrReverse(ByVal str As String)
Dim str2 As String = ""
Dim cs As Char() = str.ToCharArray()
For i As Integer = cs.Length - 1 To 0 Step -1
str2 = str2 + cs(i)
Next
Return str2
End Function
在VB中,创建程序,将输入的字符串颠倒输出,要求用DO While和Do until 实现
用 Do While 实现:
Private Sub Form_Click() '点击窗体运行
s = InputBox("请输入一个字符串")
n = 1
t = ""
Do While n = Len(s)
t = Mid(s, n, 1) t
n = n + 1
Loop
MsgBox "颠倒输出 " t
End Sub
用 Do Until 实现:
Private Sub Form_Click() '点击窗体运行
s = InputBox("请输入一个字符串")
n = 1
t = ""
Do Until n Len(s)
t = Mid(s, n, 1) t
n = n + 1
Loop
MsgBox "颠倒输出 " t
End Sub
友情附赠最简单的实现方法:
Private Sub Form_Click() '点击窗体运行
MsgBox "颠倒输出 " StrReverse(InputBox("请输入一个字符串"))
End Sub
VB.NET中如何将一个转化为字符串,并取它的每一个字符
VB.NET 整型 i 转化为字符串 s , 字符串 s 转化为字符数组 CharArr :
Dim i As Integer = 12345
Dim s As String
Dim CharArr As Char()
s = i.ToString()
CharArr = s.ToCharArray()
将 CharArr 数组反转:
Array.Reverse(CharArr)
VB.NET中字符串倒序的问题
好象有个StrReverse函数是直接反转字符串的吧..
我平时用的是VB6.但是.NET中应该也是可以用MID的
你注意看FOR 是从len-1到0的..而mid中是不允许出现0的..
你看看MID运行不了时,是不是返回I是0的时间
改成:
For i = Len(sstr) To 1 Step -1
试试了?
当前标题:vb.net字符串反转 C#字符串反转
网页URL:http://hbruida.cn/article/hipddj.html