VB.NET编程语言的出现,在一定程度上改变了编程人员的开发方式,提高了开发人员程序开发效率。在实际编程中,对于字符的操作是比较常见的。这里为大家带来的就是VB.NET字符转换的相关实现方法。#t#
VB.NET字符转换代码操作实例:
- Public Function ToSBC()Function
ToSBC(ByVal input As String)
As String '转全角 - Dim c As Char() = input.
ToCharArray - Dim i As Integer = 0
- While i < c.Length
- If c(i) = ChrW(32) Then
- c(i) = ChrW(12288)
- ElseIf AscW(c(i)) < 127 Then
- c(i) = ChrW((AscW(c(i)) + 65248))
- End If
- System.Math.Min(System.Threading.
Interlocked.Increment(i), i - 1)- End While
- Return New String(c)
- End Function
- Public Function ToDBC()Function
ToDBC(ByVal input As String)
As String '转半角- Dim c As Char() = input.ToCharArray
- Dim i As Integer = 0
- While i < c.Length
- If AscW(c(i)) = 12288 Then
- c(i) = ChrW(32)
- ElseIf AscW(c(i)) > 65280 AndAlso
AscW(c(i)) < 65375 Then- c(i) = ChrW(AscW(c(i)) - 65248)
- End If
- System.Math.Min(System.Threading.
Interlocked.Increment(i), i - 1)- End While
- Return New String(c)
- End Function
VB.NET字符转换相关实现操作就为大家介绍到这里。