Solved

Conversion of  Arabic to Database Compatiable

Posted on 2011-03-22
7
562 Views
Last Modified: 2012-05-11
We have to develop a C#.Net (VS 2008) Windows application on top of an exisitng legacy SQL2000 database. These database contain some tables with Arabic data stored with data type varchar.
While reviewing the same, we foudn that the arabic data is stored in some format which we are not aware of.  However we found a way to display the same data into C# edit box using the following Function

 private string ToArabic(string text)
    {
      byte[] bytes = new byte[text.Length];
      for (int i = 0; i < text.Length; i++)
        bytes[i] = (byte)text[i];
      
      return System.Text.Encoding.GetEncoding(1256).GetString(bytes);
    }

Open in new window


This will convert  ÓíãÇÌí       to ¿¿¿¿¿¿

We are now in search of a reverse function. i.e Arabic to Database Format.
If user enters ¿¿¿¿¿¿ , it should convert to ÓíãÇÌí

We need a way to store any arabic data eneterd  by user in a C# edit box to the database in the same format in which it currently holds arabic data. We are forbidden from making any changes to the way in which data is stored in database

Examples of data stored in database on left and how it gets converted to Arabic(on right) using the function above is shown below
ÓíãÇÌí      ¿¿¿¿¿¿
Ñãíæ      ¿¿¿¿
ÚÈÏÇáÓáÇã      ¿¿¿¿¿¿¿¿¿

We need a way to convert the same back . This is urgent and hence 500 points. Please help
0
Comment
Question by:GEMINI-INDIA
  • 4
  • 2
7 Comments
 

Author Comment

by:GEMINI-INDIA
ID: 35188742
Please refer the attached image as in the conversion shown in the question, the ARabic has not come out correctly(editor limiation) Conversion of Data to Arabic
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 35188769
>> We are now in search of a reverse function. i.e Arabic to Database Format.

I need to clarify you better..
Arabic characters are considered as unicode characters and hence it has to be stored in either nchar() or nvarchar().
Seems like you have saved Arabic characters into a table with column datatype either char() or varchar() which doesn't have the ability to store unicode values and hence when you inserted Arabic data is inserted into your table, you have lost the Arabic data ( and hence ¿¿¿¿¿¿ is not Database format)

In order to store Arabic data, you need to store it in column with datatype either nchar() or nvarchar() only.
While inserting Arabic data into the table, Unicode(arabic) characters needs to be prefixed with N like shown below

INSERT into ur_table ( arabic_data_column)
VALUES (N'abc');

assuming 'abc' is Arabic data..

Hope this clarifies.
0
 

Author Comment

by:GEMINI-INDIA
ID: 35188886
Hi,
Thanks for the reply. However there seems to be some confusion on the requirement. Please refer to our question again. We have no control on the database and how it stores data.(It is accessed by other applications also).  Please also note that  ¿¿¿¿¿¿  is not the issue as it was only an editor issue in Experts exhange.  Please refer to the addendum image comment to our first question in which the conversion of characters like ÓíãÇÌí      has been successfuly done by the function mentioned. We are looking for a reverse function which will convert arabic to the formats like ÓíãÇÌí      

Hope this clarifies
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 35189110
>> We are now in search of a reverse function. i.e Arabic to Database Format.

Ok, got your situation clear now..
Since it is the logic already used by the application, instead of re-inventing the wheel you can use the logic done over there itself right
Or else, just use the appropriate decoding for the encoding done in the code posted above.
0
 

Author Comment

by:GEMINI-INDIA
ID: 35189168
Hi,
Thanks for the reply. However we are creating a new application and have no idea how the exisitng application(by other providers) managed to save Arabic data in format like  ÓíãÇÌí
into the database

However we have found a mechanism to convert ÓíãÇÌí  to arabic using function below

private string ToArabic(string text)
    {
      byte[] bytes = new byte[text.Length];
      for (int i = 0; i < text.Length; i++)
        bytes[i] = (byte)text[i];
      
      return System.Text.Encoding.GetEncoding(1256).GetString(bytes);
    }

Open in new window


We now need a reverse function to convert Arabic from our new application to format like ÓíãÇÌí  so that our data saving to the database does not affect other applications
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 35190632
I think it should be:

private string ToArabicReverse(string text)
    {
      byte[] bytes = System.Text.Encoding.GetEncoding(1256).GetBytes(text);
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < bytes.Length; i++)
        sb.Append((char)bytes[i]);
      
      return sb.ToString();
    }

Open in new window


BTW, 1256 is called Arabic (Windows) encoding.

I hope this helps.
0
 

Author Comment

by:GEMINI-INDIA
ID: 35195928
Thank you wdosanjos. Your solution works. Points awarded

Thanks again
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now