Results 1 to 16 of 16

Thread: [RESOLVED] Unicdoe

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    37

    Resolved [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!!!

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    37

    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 ?

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    37

    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

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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?

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    37

    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

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    37

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

  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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).

  11. #11
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    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.

  12. #12

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    37

    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.

  13. #13

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    37

    Re: Unicdoe

    the arabic text is السلام عليكم

  14. #14
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    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:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.     '   Using a Big Endian Unicode encoding (utf-16BE)
    4.     '     as is required for the desired output format
    5.     Dim enc As Encoding = System.Text.Encoding.GetEncoding("utf-16BE")
    6.  
    7.     '   Encode the string to a byte array
    8.     Dim realStr As String = "السلام عليكم"
    9.     Dim bArr As Byte() = enc.GetBytes(realStr)
    10.  
    11.     '   build the hex string using a StringBuilder
    12.     Dim hexStrBuilder As New System.Text.StringBuilder
    13.     For i = 0 To bArr.Length - 1
    14.         hexStrBuilder.Append(bArr(i).ToString("X2"))
    15.     Next
    16.  
    17.     '   Convert the value of the StringBuilder
    18.     '     to a String value for display
    19.     Dim hexStr As String = hexStrBuilder.ToString
    20.  
    21.  
    22.     '   display the results
    23.     MessageBox.Show(hexStr)
    24.  
    25. End Sub

    The above outputs 062706440633064406270645002006390644064A06430645
    from "السلام عليكم"

  15. #15

    Thread Starter
    Member
    Join Date
    Feb 2013
    Posts
    37

    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.

  16. #16
    New Member
    Join Date
    Dec 2019
    Posts
    2

    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
  •  



Click Here to Expand Forum to Full Width