1

How can I send an SMS in hebrew through Clickatell?

It arrives on the device as gibberish.

darryn.ten
  • 6,784
  • 3
  • 47
  • 65
flybywire
  • 261,858
  • 191
  • 397
  • 503

5 Answers5

3

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)));
Kev
  • 118,037
  • 53
  • 300
  • 385
evyevy
  • 31
  • 4
1

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.

    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();
    }
Ross Jones
  • 11
  • 1
1

Is it in unicode ? If I remember correctly they require unicode to be escaped into hexadecimal representation. This should be in their docs.

However, I found out when I did this that this is not the only issue, many phones do not support displaying unicode characters properly.

Also, sending unicode may incur a higher cost since it may be split up.

PQW
  • 1,147
  • 6
  • 6
1

Encode your message as unicode, see this FAQ page for details.

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
0

I used following logic for arabic .. IT needs more testing . Language is 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)

    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

makdu
  • 908
  • 2
  • 13
  • 26