Hi,
I want to send an arabic sms from vb.net windows application. In order to send I have to convert the arabic text to unicode. How can I convert arabic text to unicode..
Thanks in advance!!!
Printable View
Hi,
I want to send an arabic sms from vb.net windows application. In order to send I have to convert the arabic text to unicode. How can I convert arabic text to unicode..
Thanks in advance!!!
Arabic text should be in Unicode to begin with. It would be easier to answer your question if you provide some of the code.
Thanks for your reply.
the scenario is on entering msg content and mobile no. and clicking send sms button the message should go...
for english im doing it by setting the url of webbrower control...and making webbrowser control invisible...
for arabic i have to convert it into unicode...Is there any function for converting text to unicode ?
I'm sorry but this doesn't make any sense. Setting an url of a webbrowser does not send any text messages to a phone. You must provide more information on how you're sending a text message.
I have got an api from sms provider ..in that api has parameters for mobile no,username,password, message etc...im able to send english sms ...i can send arabic if in the message parameter i provide unicode of arabic text...I dont know the funciton to convert text to unicode...hope now you got my problem
Internally VB stores strings in Unicode format. You might use the StrConv function, but there is no way I can tell you that for sure without seeing some code. Is the API a .Net assembly, a P/Invoke or COM object? How is it declared?
Dim url As String
url = "http://weburl.jsp?usr=abc&pass=def&msisdn=95786123384645&sid=ABC&msg=welcome&mt=0"
webbrowser1.navigate(url)
the url i got from provider. Is there any other better way of sending sms using api ?
sms provider told to send arabic, in place of welcome i have to put the unicode value of the arabic text and mt parameter has to be set to 3
thats the reason im asking to convert arabic text to unicode
OK, so you want to send unicode characters as part of the URL string. In that case you need to encode them. It's done in this way: %NN where NN is two hexadecimal characters representing the unicode char. If you have Google Chrome or Firefox you can actually type in the arabic text as part of the URL. Copy it from there and paste it into IE and you'll see the encoding.
ya i can do it form browser but the problem is i want it dynamic...I mean the user will give message at run time....thats why I need a vb.net function to encode it....
Yes, however I don't know the encodings for Arabic that's why I suggested that you used the browser to figure them out yourself. Once you've figured out what various characters translate into then you can build it yourself (hopefully).
I am wondering if you could use the HttpUtility Class to encode the message into the required format.
To use the HttpUtility Class, make sure you are not targeting one of the client frameworks, and add a reference to System.Web (from the .NET tab of the Add Reference dialogue).
Take a look at its UrlEncode(String) and UrlPathEncode methods. There is a difference in the way they handle the Space character. There is also a UrlEncodeUnicode method, but I doubt the output it produces is what you need. Anyway, have a play and see if anything there works.
An example of how to use them would be
which produce output like:Code:Dim message As String = "وابل من النيازك يضرب الاورال بروسيا"
Dim encodedMessage As String = System.Web.HttpUtility.UrlEncode(message)
Dim pathEencodedMessage As String = System.Web.HttpUtility.UrlPathEncode(message)
MessageBox.Show(message & Environment.NewLine & encodedMessage)
MessageBox.Show(message & Environment.NewLine & pathEencodedMessage)
original:
وابل من النيازك يضرب الاورال بروسيا
UrlEncode:
%d9%88%d8%a7%d8%a8%d9%84+%d9%85%d9%86+%d8%a7%d9%84%d9%86%d9%8a%d8%a7%d8%b2%d9%83+%d9%8a%d8%b6%d8%b1% d8%a8+%d8%a7%d9%84%d8%a7%d9%88%d8%b1%d8%a7%d9%84+%d8%a8%d8%b1%d9%88%d8%b3%d9%8a%d8%a7
UrlPathEncode
%d9%88%d8%a7%d8%a8%d9%84%20%d9%85%d9%86%20%d8%a7%d9%84%d9%86%d9%8a%d8%a7%d8%b2%d9%83%20%d9%8a%d8%b6% d8%b1%d8%a8%20%d8%a7%d9%84%d8%a7%d9%88%d8%b1%d8%a7%d9%84%20%d8%a8%d8%b1%d9%88%d8%b3%d9%8a%d8%a7
I have no idea what that says, but hopefully it won't be anything offensive as it comes from a BBC web site. :)
I want output in format 062706440633064406270645002006390644064a06430645 for arabic text as السلام عليكم
I have below code which is not giving the exact output...if anyone can help!!
Dim bArr As Byte() = System.Text.Encoding.Unicode.GetBytes(RealStr)
Dim hexStr As String = ""
For i = 0 To bArr.Length - 1 Step -2
hexStr += BitConverter.ToString(New Byte() {bArr(i), bArr(i + 1)})
Next
RichTextBox1.Text = hexStr.ToString()
the arabic text is السلام عليكم
Your For Loop is starting at 0 and stepping -2 which isn't helping (the code in the loop never actually executes).
The following should help get you started:Code:For i = 0 To bArr.Length - 1 Step -2
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Using a Big Endian Unicode encoding (utf-16BE) ' as is required for the desired output format Dim enc As Encoding = System.Text.Encoding.GetEncoding("utf-16BE") ' Encode the string to a byte array Dim realStr As String = "السلام عليكم" Dim bArr As Byte() = enc.GetBytes(realStr) ' build the hex string using a StringBuilder Dim hexStrBuilder As New System.Text.StringBuilder For i = 0 To bArr.Length - 1 hexStrBuilder.Append(bArr(i).ToString("X2")) Next ' Convert the value of the StringBuilder ' to a String value for display Dim hexStr As String = hexStrBuilder.ToString ' display the results MessageBox.Show(hexStr) End Sub
The above outputs 062706440633064406270645002006390644064A06430645
from "السلام عليكم"
@Inferrd
Wow it worked ...thanks a lot...milliion thanks to you....really i was searching this for a long time....how you people know all this stuffs...?Please suggest how to I can try to reach you people's experience level...:)
and that -2 was by mistake it was 2 and I was doing test by changing values...like
For i =bArr.Length - 1 to 0 Step -2
and while copying here i forgot to make -2 to 2
6 years later, you're the MVB... I can't tell you how bad the Arabic programming community at helping with this, thank you thank you thank you