Click here to Skip to main content
15,922,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: string==C#?YES:NO Pin
leppie8-Jul-04 9:37
leppie8-Jul-04 9:37 
GeneralRe: string==C#?YES:NO Pin
saud_a_k8-Jul-04 19:32
saud_a_k8-Jul-04 19:32 
GeneralRe: string==C#?YES:NO Pin
leppie9-Jul-04 7:06
leppie9-Jul-04 7:06 
GeneralRe: string==C#?YES:NO Pin
saud_a_k12-Jul-04 18:36
saud_a_k12-Jul-04 18:36 
GeneralQuestion about NavigationGraph in UIPAB Pin
Phoenixcp7-Jul-04 21:52
Phoenixcp7-Jul-04 21:52 
GeneralRe: Question about NavigationGraph in UIPAB Pin
Heath Stewart8-Jul-04 5:14
protectorHeath Stewart8-Jul-04 5:14 
GeneralASCII code for Arabic(Farsi) letters Pin
Hovik Melkomian7-Jul-04 21:17
Hovik Melkomian7-Jul-04 21:17 
GeneralRe: ASCII code for Arabic(Farsi) letters Pin
Heath Stewart8-Jul-04 4:30
protectorHeath Stewart8-Jul-04 4:30 
First you need to understand that all characters (and hence, all strings) are treated as Unicode in .NET (strings are even stored as Unicode in the assembly).

You can, however, use the Encoding class with the proper codepage.

See, ASCII is actually 7bit characters. Anything over 127 requires a codepage in order to resolve the symbols correctly.

To get the codepage for Farsi, you can either refer to it by the codepage, or if you don't know it do something like this:
CultureInfo ci = new CultureInfo("ar");
int codepage = ci.TextInfo.ANSICodePage;
If you read the class documentation for the CultureInfo class in the .NET Framework SDK, you can find the LCIDs and culture name abbreviations (like "en-US" for "English (United States)"). For a non-regional Arabic language, you can use the LCID 0x01 (1).

So, to get an Encoding for that codepage, do this:
Encoding enc = Encoding.GetEncoding(0x04e8);
byte[] buffer = enc.GetBytes(yourFarsiString);
foreach (byte b in buffer)
  Console.Write(b.ToString("x2"));
Console.WriteLine();


Here's an example of decoding a Unicode string I assume says "Hello" (in Farsi) into ANSI characters using the Farsi codepage:
using System;
using System.Globalization;
using System.Text;
 
class Test
{
  static void Main()
  {
    CultureInfo ci = new CultureInfo("ar");
    int codepage = ci.TextInfo.ANSICodePage;
    Console.WriteLine("Using codepage 0x{0:x4}", codepage);
 
    string str = "\ufeed\ufee0\ufe8e\ufeeb";
    Console.WriteLine("Decoding " + str);
 
    Encoding enc = Encoding.GetEncoding(codepage);
    byte[] buffer = enc.GetBytes(str);
    foreach (byte b in buffer)
      Console.Write("0x{0:x2} ", b);
 
    Console.WriteLine();
  }
}


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: ASCII code for Arabic(Farsi) letters Pin
Hovik Melkomian13-Jul-04 3:29
Hovik Melkomian13-Jul-04 3:29 
GeneralRe: ASCII code for Arabic(Farsi) letters Pin
Heath Stewart13-Jul-04 3:42
protectorHeath Stewart13-Jul-04 3:42 
GeneralRe: ASCII code for Arabic(Farsi) letters Pin
Hovik Melkomian13-Jul-04 20:38
Hovik Melkomian13-Jul-04 20:38 
GeneralRe: ASCII code for Arabic(Farsi) letters Pin
Heath Stewart14-Jul-04 3:06
protectorHeath Stewart14-Jul-04 3:06 
GeneralRe: ASCII code for Arabic(Farsi) letters Pin
Hovik Melkomian15-Jul-04 4:24
Hovik Melkomian15-Jul-04 4:24 
GeneralRe: ASCII code for Arabic(Farsi) letters Pin
Heath Stewart19-Jul-04 2:10
protectorHeath Stewart19-Jul-04 2:10 
QuestionHow do Compare two DataTable Pin
jzb7-Jul-04 20:55
jzb7-Jul-04 20:55 
AnswerRe: How do Compare two DataTable Pin
Heath Stewart8-Jul-04 4:03
protectorHeath Stewart8-Jul-04 4:03 
GeneralArticle submission question… Pin
Ray Cassick7-Jul-04 18:59
Ray Cassick7-Jul-04 18:59 
GeneralRe: Article submission question… Pin
Heath Stewart8-Jul-04 3:58
protectorHeath Stewart8-Jul-04 3:58 
GeneralC# class and COM+ issue Pin
hatim_ali7-Jul-04 18:57
hatim_ali7-Jul-04 18:57 
Generalabout software error detecting Pin
fu07-Jul-04 18:44
fu07-Jul-04 18:44 
QuestionEnvironment.SpecialFolder ?? Pin
azusakt7-Jul-04 17:45
azusakt7-Jul-04 17:45 
AnswerRe: Environment.SpecialFolder ?? Pin
Judah Gabriel Himango7-Jul-04 18:44
sponsorJudah Gabriel Himango7-Jul-04 18:44 
GeneralHOWTO: UserControl + Form Pin
Binoy Patel7-Jul-04 16:02
Binoy Patel7-Jul-04 16:02 
GeneralOutlook "like" Date Groupings Pin
pgraeve7-Jul-04 12:58
pgraeve7-Jul-04 12:58 
GeneralRe: Outlook "like" Date Groupings Pin
Werdna7-Jul-04 18:55
Werdna7-Jul-04 18:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.