最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

VBS字符串編碼轉換函數(shù)代碼

 更新時間:2023年04月12日 10:49:07   作者:薛定諤的青蛙王梓  
這篇文章主要介紹了vbs字符串在不同編碼之間的轉換,包括?ISO-8859-1,UTF-8,GBK,GB2312,GB18030之間的轉換,需要的朋友可以參考下

因為業(yè)務需要將一些字符串轉換為指定編碼方便后期操作

核心代碼

Const adTypeBinary = 1
Const adTypeText = 2

' accept a string and convert it to Bytes array in the selected Charset
Function StringToBytes(Str,Charset)
  Dim Stream : Set Stream = CreateObject("ADODB.Stream")
  Stream.Type = adTypeText
  Stream.Charset = Charset
  Stream.Open
  Stream.WriteText Str
  Stream.Flush
  Stream.Position = 0
  ' rewind stream and read Bytes
  Stream.Type = adTypeBinary
  StringToBytes= Stream.Read
  Stream.Close
  Set Stream = Nothing
End Function

' accept Bytes array and convert it to a string using the selected charset
Function BytesToString(Bytes, Charset)
  Dim Stream : Set Stream = CreateObject("ADODB.Stream")
  Stream.Charset = Charset
  Stream.Type = adTypeBinary
  Stream.Open
  Stream.Write Bytes
  Stream.Flush
  Stream.Position = 0
  ' rewind stream and read text
  Stream.Type = adTypeText
  BytesToString= Stream.ReadText
  Stream.Close
  Set Stream = Nothing
End Function

' This will alter charset of a string from 1-byte charset(as windows-1252)
' to another 1-byte charset(as windows-1251)
Function AlterCharset(Str, FromCharset, ToCharset)
  Dim Bytes
  Bytes = StringToBytes(Str, FromCharset)
  AlterCharset = BytesToString(Bytes, ToCharset)
End Function

使用例子:

dim s1,s2,FromCharset,ToCharset
s1 = "我的字符串之腳本之家"
FromCharset = "GB2312"
ToCharset = "ISO-8859-1"
s2 = AlterCharset(s1,FromCharset,ToCharset)

到此這篇關于VBS字符串編碼轉換函數(shù)代碼的文章就介紹到這了,更多相關VBS編碼轉換內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

册亨县| 肥东县| 高州市| 盘锦市| 霍州市| 雅安市| 泰宁县| 正宁县| 富民县| 樟树市| 桐乡市| 贺州市| 石狮市| 大余县| 南华县| 丰镇市| 潮安县| 抚松县| 内江市| 海城市| 调兵山市| 绥阳县| 娱乐| 佛冈县| 兰溪市| 那坡县| 沾益县| 晋宁县| 滁州市| 双江| 崇左市| 尉犁县| 大渡口区| 吴忠市| 蚌埠市| 桐柏县| 奉化市| 车险| 永清县| 封开县| 东乡族自治县|