真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

vb.net字符編碼校驗,vb驗證碼代碼

gb2312>unicode>utf8, 以及逆轉(zhuǎn)的方法'>VB.net 字符轉(zhuǎn)換問題 字符(漢字、數(shù)字、字母、符號)>gb2312>unicode>utf8, 以及逆轉(zhuǎn)的方法

字符編碼轉(zhuǎn)換嗎?

10年積累的網(wǎng)站制作、成都網(wǎng)站制作經(jīng)驗,可以快速應對客戶對網(wǎng)站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認識你,你也不認識我。但先網(wǎng)站設(shè)計后付款的網(wǎng)站建設(shè)流程,更有內(nèi)黃免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。

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

'轉(zhuǎn)化為字節(jié)碼

For i As Integer = 1 To n

sBytes(i - 1) = CByte("H" sInput.Substring(2 * i - 2, 2))

Next

'將字節(jié)碼轉(zhuǎn)化為字符串

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.NET如何對輸入的數(shù)據(jù)進行合法性檢驗,過濾不合法的數(shù)據(jù)代碼

合法性校驗有很多方法,要視情況而定,比如說可以用正則表達式,如果是數(shù)字,除了正則表達式,也可以用諸如TryParse這種方法。

vb.net怎么把漢字轉(zhuǎn)換為GB2312編碼,例如“廣東”變成%B9%E3%B6%AB

GB2312是GBK編碼的子集,使用GBK編碼函數(shù)即可

'GBK編碼(結(jié)果以百分號%進行分隔)

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

'轉(zhuǎn)化為字節(jié)碼

For i As Integer = 1 To n

sBytes(i - 1) = CByte("H" sInput.Substring(2 * i - 2, 2))

Next

'將字節(jié)碼轉(zhuǎn)化為字符串

ret_GBKDecode = System.Text.Encoding.Default.GetString(sBytes)

Return ret_GBKDecode

End Function


本文標題:vb.net字符編碼校驗,vb驗證碼代碼
文章來源:http://weahome.cn/article/dsecsdi.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部