VBS字符串编码转换函数代码怎么写 您所在的位置:网站首页 vba转换utf8字符串 VBS字符串编码转换函数代码怎么写

VBS字符串编码转换函数代码怎么写

2023-05-19 07:47| 来源: 网络整理| 查看: 265

VBS字符串编码转换函数代码怎么写 发布时间:2023-05-08 14:33:12 来源:亿速云 阅读:83 作者:zzz 栏目:开发技术

这篇“VBS字符串编码转换函数代码怎么写”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“VBS字符串编码转换函数代码怎么写”文章吧。

因为业务需要将一些字符串转换为指定编码方便后期操作

核心代码

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字符串编码转换函数代码怎么写”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。

推荐阅读: vbs中如何获取Am注册路径信息 vbs中提示没有在该机执行windows脚本宿主的权限怎么解决

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:[email protected]进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vbs 上一篇新闻:Oracle空闲超时时间如何设置 下一篇新闻:java数据结构单向链表的操作有哪些 猜你喜欢 ASP.NET对大文件上传的解决方法 VS2010新建站点发布并访问的步骤详解 VS2012发布网站的详细步骤 如何编写ASP.NET实现动态GIF验证码 如何在Asp.net项目中实现一个下拉树功能 如何实现Asp.Mvc 2.0用户的编辑与删除 怎么在.NET中删除空白的字符串 如何实现Asp.Mvc 2.0用户服务器验证 使用ASP.NET怎么实现一个用户注册功能 如何使用ASP.NET添加数据


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有