问题描述
我需要使用 VB.NET 将 UTF8 字符串转换为 ISO-8859-1 字符串.
I need to convert UTF8 string to ISO-8859-1 string using VB.NET.
有什么例子吗?
强调文本我尝试过拉丁函数但没有运行.我收到错误的字符串.
emphasized textI have tried Latin function and not runs. I receive incorrect string.
我的情况是我需要使用 API 发送短信.
My case is that I need to send SMS using API.
现在我有了这个代码:
baseurl = "http://www.myweb.com/api/sendsms.php"
client = New WebClient
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")
client.Encoding = System.Text.Encoding.GetEncoding("ISO-8859-1")
client.QueryString.Add("user", user)
client.QueryString.Add("password", pass)
client.QueryString.Add("alias", myAlias)
client.QueryString.Add("dest", mobile)
textoSms = Me.mmTexto.Text
textoSms = System.Web.HttpUtility.UrlEncode(textoSms)
client.QueryString.Add("message", textoSms)
data = client.OpenRead(baseurl)
reader = New StreamReader(data)
s = reader.ReadToEnd()
data.Close()
reader.Close()
但不能运行...我收到不正确的消息.例如
But not runs...I receive incorrect messages. For example
如果我写:mañana 返回 maa ana
如果我写 aigüa 返回 aiga
推荐答案
怎么样:
Dim converted as Byte() = Encoding.Convert(utf8, Encoding.UTF8, _
Encoding.GetEncoding(28591))
假设当您说UTF8 字符串"时,您的意思是二进制数据,它是某些文本的 UTF-8 表示".如果你的意思是别的,请说明:)
That assumes that when you say "UTF8 string" you mean "binary data which is the UTF-8 representation of some text". If you mean something else, please specify :)
请注意,ISO-8859-1 仅代表完整 Unicode 的一小部分.IIRC,你最终会得到?"对于 ISO-8859-1 中不可用的源数据中的任何字符.
Note that ISO-8859-1 only represents a tiny proportion of full Unicode. IIRC, you'll end up with "?" for any character from the source data which isn't available in ISO-8859-1.
这篇关于将 UTF8 字符串编码为 ISO-8859-1 字符串 (VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!