Solved

Conversion of  Arabic to Database Compatiable

Posted on 2011-03-22
7
581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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