-
Feb 16th, 2013, 12:54 AM
#1
Thread Starter
Member
[RESOLVED] Unicdoe
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!!!
-
Feb 16th, 2013, 01:16 AM
#2
Re: Unicdoe
Arabic text should be in Unicode to begin with. It would be easier to answer your question if you provide some of the code.
-
Feb 16th, 2013, 02:08 AM
#3
Thread Starter
Member
Re: Unicdoe
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 ?
-
Feb 16th, 2013, 02:27 AM
#4
Re: Unicdoe
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.
-
Feb 16th, 2013, 02:38 AM
#5
Thread Starter
Member
Re: Unicdoe
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
-
Feb 16th, 2013, 03:00 AM
#6
Re: Unicdoe
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?
-
Feb 16th, 2013, 03:34 AM
#7
Thread Starter
Member
Re: Unicdoe
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
-
Feb 16th, 2013, 05:50 AM
#8
Re: Unicdoe
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.
-
Feb 16th, 2013, 08:12 AM
#9
Thread Starter
Member
Re: Unicdoe
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....
-
Feb 16th, 2013, 09:07 AM
#10
Re: Unicdoe
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).
-
Feb 16th, 2013, 10:51 AM
#11
Re: Unicdoe
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
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)
which produce output like:
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.
Last edited by Inferrd; Feb 16th, 2013 at 11:07 AM.
-
Mar 24th, 2013, 02:00 AM
#12
Thread Starter
Member
Re: Unicdoe
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()
Last edited by afreen; Mar 24th, 2013 at 02:04 AM.
-
Mar 24th, 2013, 02:01 AM
#13
Thread Starter
Member
Re: Unicdoe
the arabic text is السلام عليكم
-
Mar 24th, 2013, 02:55 AM
#14
Re: Unicdoe
Your For Loop is starting at 0 and stepping -2 which isn't helping (the code in the loop never actually executes).
Code:
For i = 0 To bArr.Length - 1 Step -2
The following should help get you started:
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 "السلام عليكم"
-
Mar 24th, 2013, 04:48 AM
#15
Thread Starter
Member
Re: Unicdoe
@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
Last edited by afreen; Mar 24th, 2013 at 04:54 AM.
-
Dec 14th, 2019, 09:03 PM
#16
New Member
Re: Unicdoe
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|