I am developing an SMS application using C# for the bank which sends transaction alerts i.e. ATM transactions to the customer through the SMS gateway. The application is working fine, the only issue is encoding the Persian text, it doesn't encode the Persian text correctly.
Here is the method which encodes Persian text to UTF-16 format.
public static string Endian2UTF(string s)
{
Encoding ui = Encoding.BigEndianUnicode;
Encoding u8 = Encoding.UTF8;
string str = u8.GetString(ui.GetBytes(s));
return str;
}
Some characters are not getting encoded correctly, the message on mobile device looks like as below
مشترۯ뾽 ۯ뾽رامۯ뾽 شما به مقدار 500.00 افغانۯ뾽 از حساب خوب از ماشۯ뾽ن صرافۯ뾽 نماۯ뾽ندۯ뾽ۯ뾽 شهر نو بدست اوردۯ뾽د، تشۯ뾽ر از شما.
The issue is only with some characters as you see above. For your information, there is no issue with the English string.