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
Solved

Conversion of  Arabic to Database Compatiable

Posted on 2011-03-22
7
573 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

In this article I will describe the Detach & Attach 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.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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