How can I send an SMS in hebrew through Clickatell?
如何通过Clickatell发送希伯来语短信?
It arrives on the device as gibberish.
它作为胡言乱语到达设备。
5 个解决方案
#1
Is it in unicode ? If I remember correctly they require unicode to be escaped into hexadecimal representation. This should be in their docs.
它是unicode吗?如果我没记错的话,他们需要将unicode转义为十六进制表示。这应该在他们的文档中。
However, I found out when I did this that this is not the only issue, many phones do not support displaying unicode characters properly.
但是,当我这样做时,我发现这不是唯一的问题,许多手机不支持正确显示unicode字符。
Also, sending unicode may incur a higher cost since it may be split up.
此外,发送unicode可能会产生更高的成本,因为它可能会被拆分。
#2
I couldn't find any working example so, i wrote my own:
我找不到任何有效的例子,我写了自己的:
Try this:
UnicodeEncoding unicode = new UnicodeEncoding(true, false);
return string.Concat(unicode.GetBytes(val).Select(c => string.Format("{0:x2}", c)));
#3
Encode your message as unicode, see this FAQ page for details.
将您的邮件编码为unicode,有关详细信息,请参阅此常见问题解答页面。
#4
Ran into the same issue... you need to encode to unicode and then convert to hex. The strange thing is that you need to take the last value and append it to the front in order to get it to work. I found this out by comparing the results of my code against the output of their online tool.
遇到同样的问题......你需要编码为unicode然后转换为十六进制。奇怪的是,您需要获取最后一个值并将其附加到前面才能使其正常工作。我通过比较我的代码的结果和他们的在线工具的输出找到了这一点。
private string ToUnicode(string val)
{
Encoding utf8 = Encoding.UTF8;
Encoding unicode = Encoding.Unicode;
byte[] utf8Bytes = utf8.GetBytes(val);
byte[] unicodeBytes = Encoding.Convert(utf8, unicode, utf8Bytes);
var result = ByteArrayToString(unicodeBytes);
result = result.Substring(result.Length - 2, 2) + result.Substring(0, result.Length - 2);
return result;
}
public static string ByteArrayToString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
hex.AppendFormat("{0:x2}", b);
return hex.ToString();
}
#5
I used following logic for arabic .. IT needs more testing . Language is VB.Net
我使用了以下阿拉伯语逻辑.. IT需要更多测试。语言是VB.Net
If txtArabic.Text.Trim.Length > 0 Then
Dim unicodeString As String = txtArabic.Text
Dim unicode As Encoding = Encoding.Unicode
' Convert the string into a byte array.
Dim unicodeBytes As Byte() = unicode.GetBytes(unicodeString)
Dim sb As String = ToUnicode(txtArabic.Text)
End If
Here is the conversion part
这是转换部分
Private Function ToUnicode(ByVal strVal As String)
私有函数ToUnicode(ByVal strVal As String)
Dim unicode As Encoding = New UnicodeEncoding(True, False)
' Encoding.Unicode
Dim utf8 As Encoding = Encoding.UTF8
Dim utf8Bytes() As Byte = unicode.GetBytes(strVal)
Dim unicodeBytes() As Byte = Encoding.Convert(utf8, unicode, utf8Bytes)
Dim result As String = ByteArrayToString(unicodeBytes)
Return result
End Function
Private Function ByteArrayToString(ByVal ba() As Byte)
Dim hex As StringBuilder = New StringBuilder(ba.Length)
For i As Integer = 0 To ba.Length - 1
If (((i - 2) Mod 4.0) = 0) Then
Else
hex.AppendFormat("{0:x00}", ba(i))
' hex.Append(ba(i))
End If
' hex.Append("-")
Next
Return hex.ToString
End Function
#1
Is it in unicode ? If I remember correctly they require unicode to be escaped into hexadecimal representation. This should be in their docs.
它是unicode吗?如果我没记错的话,他们需要将unicode转义为十六进制表示。这应该在他们的文档中。
However, I found out when I did this that this is not the only issue, many phones do not support displaying unicode characters properly.
但是,当我这样做时,我发现这不是唯一的问题,许多手机不支持正确显示unicode字符。
Also, sending unicode may incur a higher cost since it may be split up.
此外,发送unicode可能会产生更高的成本,因为它可能会被拆分。
#2
I couldn't find any working example so, i wrote my own:
我找不到任何有效的例子,我写了自己的:
Try this:
UnicodeEncoding unicode = new UnicodeEncoding(true, false);
return string.Concat(unicode.GetBytes(val).Select(c => string.Format("{0:x2}", c)));
#3
Encode your message as unicode, see this FAQ page for details.
将您的邮件编码为unicode,有关详细信息,请参阅此常见问题解答页面。
#4
Ran into the same issue... you need to encode to unicode and then convert to hex. The strange thing is that you need to take the last value and append it to the front in order to get it to work. I found this out by comparing the results of my code against the output of their online tool.
遇到同样的问题......你需要编码为unicode然后转换为十六进制。奇怪的是,您需要获取最后一个值并将其附加到前面才能使其正常工作。我通过比较我的代码的结果和他们的在线工具的输出找到了这一点。
private string ToUnicode(string val)
{
Encoding utf8 = Encoding.UTF8;
Encoding unicode = Encoding.Unicode;
byte[] utf8Bytes = utf8.GetBytes(val);
byte[] unicodeBytes = Encoding.Convert(utf8, unicode, utf8Bytes);
var result = ByteArrayToString(unicodeBytes);
result = result.Substring(result.Length - 2, 2) + result.Substring(0, result.Length - 2);
return result;
}
public static string ByteArrayToString(byte[] ba)
{
StringBuilder hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
hex.AppendFormat("{0:x2}", b);
return hex.ToString();
}
#5
I used following logic for arabic .. IT needs more testing . Language is VB.Net
我使用了以下阿拉伯语逻辑.. IT需要更多测试。语言是VB.Net
If txtArabic.Text.Trim.Length > 0 Then
Dim unicodeString As String = txtArabic.Text
Dim unicode As Encoding = Encoding.Unicode
' Convert the string into a byte array.
Dim unicodeBytes As Byte() = unicode.GetBytes(unicodeString)
Dim sb As String = ToUnicode(txtArabic.Text)
End If
Here is the conversion part
这是转换部分
Private Function ToUnicode(ByVal strVal As String)
私有函数ToUnicode(ByVal strVal As String)
Dim unicode As Encoding = New UnicodeEncoding(True, False)
' Encoding.Unicode
Dim utf8 As Encoding = Encoding.UTF8
Dim utf8Bytes() As Byte = unicode.GetBytes(strVal)
Dim unicodeBytes() As Byte = Encoding.Convert(utf8, unicode, utf8Bytes)
Dim result As String = ByteArrayToString(unicodeBytes)
Return result
End Function
Private Function ByteArrayToString(ByVal ba() As Byte)
Dim hex As StringBuilder = New StringBuilder(ba.Length)
For i As Integer = 0 To ba.Length - 1
If (((i - 2) Mod 4.0) = 0) Then
Else
hex.AppendFormat("{0:x00}", ba(i))
' hex.Append(ba(i))
End If
' hex.Append("-")
Next
Return hex.ToString
End Function