How to send SMS in Hebrew using clickatell

How can I send SMS in Hebrew via Clickatell?

It comes to the device like gibberish.

+1


a source to share


5 answers


In unicode? If I remember correctly, they require unicode to be escaped to hexadecimal representation. It should be in their documents.

However, when I did this, it turned out that this is not the only problem, many phones do not support displaying Unicode characters properly.



Also, sending unicode can lead to higher cost as it can be split.

+1


a source


I couldn't find any working example, so I wrote my own:

Try the following:



UnicodeEncoding unicode = new UnicodeEncoding(true, false);
return string.Concat(unicode.GetBytes(val).Select(c => string.Format("{0:x2}", c)));

      

+3


a source


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

+1


a source


Get into the same problem ... you need to encode to unicode and then convert to hex. The weird thing is that you have to take the last value and add it to the foreground to make it work. I found this by comparing the results of my code with those of my 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();
    }

      

+1


a source


I used the following logic for Arabic. IT needs more testing. Language - 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

      

code> 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

      

code>

0


a source







All Articles