Are you looking for Win-1256 code page (Strings.Chr doesn't work with Unicode, but with code pages)?
// From arabic letter Ḍād to its one byte code (Win-1256)
byte code = Encoding.GetEncoding(1256).GetBytes("\u0636")[0];
// From code back to arabic letter
char back = Encoding.GetEncoding(1256).GetString(new byte[] { code })[0];
Console.WriteLine($"{back} == {code} (\\u{(int)back:x4})");
If you want to wrap it into a method:
private static char ArabicChr(int chrCode) {
if (chrCode < byte.MinValue || chrCode > byte.MaxValue)
throw new ArgumentOutOfRangeException(
"chrCode",
$"chrCode must be in [{byte.MinValue}..{byte.MaxValue}] range");
return Encoding.GetEncoding(1256).GetString(new byte[] { (byte)chrCode })[0];
}
Outcome:
ض == 214 (\u0636)
Edit: If you want to obtain English characters, you can try using Win-1252 code page:
private static char EnglishChr(int chrCode) {
if (chrCode < byte.MinValue || chrCode > byte.MaxValue)
throw new ArgumentOutOfRangeException(
"chrCode",
$"chrCode must be in [{byte.MinValue}..{byte.MaxValue}] range");
return Encoding.GetEncoding(1252).GetString(new byte[] { (byte)chrCode })[0];
}
In general case, if you have culture's name, e.g. "en-US"
:
private static char Chr(int chrCode, string cultureName = "en-US") {
if (chrCode < byte.MinValue || chrCode > byte.MaxValue)
throw new ArgumentOutOfRangeException(
"chrCode",
$"chrCode must be in [{byte.MinValue}..{byte.MaxValue}] range");
int page = CultureInfo.GetCultureInfo(cultureName).TextInfo.ANSICodePage;
return Encoding.GetEncoding(page).GetString(new byte[] { (byte)chrCode })[0];
}