?
Solved

Conversion of  Arabic to Database Compatiable

Posted on 2011-03-22
7
Medium Priority
?
584 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 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