1

I have an application which is developed using C#. I am using a third party API (Telnore Corporate SMS) for sending SMS to users. When I write my message in English (I am using a textbox for writing SMS) then the message delivered to mobile is fine and readable. But when I use the Urdu language instead, then it becomes something unreadable:

The delivered message looks like

I consulted multiple tutorials and techniques of UTF-8 encoding, etc., but when I used the UTF-8 encoding the delivered message still wasn't readable (everything turned to question marks in this case).

This is what I have tried so far.

string s = themessage.Text;//themessage is my textbox name

//utf8
byte[] utf = System.Text.Encoding.UTF8.GetBytes(s);
string s2 = System.Text.Encoding.UTF8.GetString(utf);
//ASCII  
byte[] utf = System.Text.Encoding.ASCII.GetBytes(s);
string s2 = System.Text.Encoding.ASCII.GetString(utf);

//Unicode 
byte[] utf = System.Text.Encoding.Unicode.GetBytes(s);
string s2 = System.Text.Encoding.Unicode.GetString(utf);

I don't know what I am doing wrong. After getting the string s2 I am passing it to a method that is sending the message.

jeffm
  • 3,120
  • 1
  • 34
  • 57
arfan
  • 21
  • 3
  • Okay, I never edited something like this in that way before, so please see my note: I *guess* that with your UTF-8 try everything turned to question marks (as did a previous editor, apparently), but in case that was not what you meant, please rephrase it again. – Gero Aug 09 '17 at 09:15
  • Also, I am not a C# dev, but have you seen [this](https://stackoverflow.com/a/14057684/710041)? I think your string is originally in default encoding, so you're constructing the byte array from the wrong encoding, perhaps? – Gero Aug 09 '17 at 09:19
  • @Gero you are right, everything is turning to question mark! – arfan Aug 09 '17 at 09:29
  • @Gero i am trying your suggested one. I hope it will work – arfan Aug 09 '17 at 09:30
  • @Gero i tried the suggested one, that didn't solve my problem. The SMS now became questions mark... – arfan Aug 09 '17 at 09:46
  • Well, as I am not a C# dev then maybe another user will be able to help. Just to make sure: The various conversions you posted in code are *alternatives*, right? You certainly commented out the ones you did not try? And you saw (& understood) that the conversion in the Q I linked uses a different encoding in each line (it's a "from-to" pattern it seems). As a non-C# person I assume that's how it works. Btw, are you sure the API accepts UTF-8? – Gero Aug 09 '17 at 09:57
  • @Gero yes i am pretty sure that is accepting. – arfan Aug 10 '17 at 03:41

0 Answers0