惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
N
Netflix TechBlog - Medium
V
Visual Studio Blog
博客园 - Franky
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
量子位
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
V
V2EX
The Cloudflare Blog
月光博客
月光博客
Last Week in AI
Last Week in AI
雷峰网
雷峰网
WordPress大学
WordPress大学
博客园 - 【当耐特】
博客园 - 聂微东
IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 半岛拖鞋

Linux下手动安装部署MySQL8.4 Flask JWT简单但完整的项目部署 定位informix oninit进程CPU占用过高的一般步骤 使用Eclipse Memory Analyzer分析java程序占用内存的情况 解决C#连接informix数据库中文乱码 Python手动新建环境 @ApiImplicitParam DataType参数的数据类型 C# Odbc Informix读取中文方法 eclise国内镜像下载地址 Spring Initializr - LSP - Failed to fetch Generation from Spring IO: port out of range: -1 oracle express 18安装后初次登录 linux 查找并批量kill进程 从WebService的SOAP返回数据中获取子级的XML内容 C# 进行用(反)序列化方法实现xml与对象进行互相转换 Alpine Linux添加中文支持显示 C#根据wsdl文件生成客户端调用代码 PHP 7.4 checking for libzip 和 failed to open error_log 问题 PHP连接Informix异常 CentOS安装扩展软件支持库
VBS字符串在不同编码之间的转换
半岛拖鞋 · 2021-09-06 · via 博客园 - 半岛拖鞋

vbscript, vbs 字符串在不同编码之间的转换,包括 ISO-8859-1,UTF-8,GBK,GB2312,GB18030之间的转换.

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)