RSS

Convert Simple Number to Arabic Number.

02 Oct

You can use this code both Web & Desktop Application.

Code 1: the HTML code:

<form id=”form1″ runat=”server”>

<asp:TextBox ID=”txtNumber” runat=”server”></asp:TextBox>

<br />

<asp:Label ID=”lblmsg” runat=”server”></asp:Label>

<br />

<asp:Button ID=”btnConvert” runat=”server” Text=”Convert to Arabic” />

</form>

 

Code 2: Code Behind

 

Protected Sub btnConvert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

 

‘Call Function

Me.lblmsg.Text = “Arabic Number : <b>” & TranslateNumerals(Me.txtNumber.Text.Trim) & “</b>”

End Sub

 

 

Public Shared Function TranslateNumerals(ByVal sIn As String) As String

 

Dim enc As New System.Text.UTF8Encoding

 

Dim utf8Decoder As System.Text.Decoder

 

utf8Decoder = enc.GetDecoder

 

Dim sTranslated = New System.Text.StringBuilder

 

Dim cTransChar(1) As Char

 

Dim bytes() As Byte = {217, 160}

 

‘ Start Converting characters into Arabic mode.

 

Dim aChars() As Char = sIn.ToCharArray

 

For Each c As Char In aChars

 

If Char.IsDigit(c) Then

 

bytes(1) = 160 + CInt(Char.GetNumericValue(c))

 

utf8Decoder.GetChars(bytes, 0, 2, cTransChar, 0)

 

sTranslated.Append(cTransChar(0))

 

Else

 

sTranslated.Append(c)

 

End If

 

Next

 

TranslateNumerals = sTranslated.ToString

 

End Function

 

 

After you run the page, enter some English number and then click “Convert to Arabic” button to display the entered number in Arabic number mode.

picArabicNo2

 
Leave a comment

Posted by on October 2, 2014 in Vb.Net

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: