问题描述
我需要使用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
推荐答案
about:
Dim converted as Byte() = Encoding.Convert(utf8, Encoding.UTF8, _
Encoding.GetEncoding(28591))
假设当你说UTF8 string是一些文本的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 String(VB.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!