Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert number to string using Hebrew letters

This is probably an easy one (it may even be a dupe), but I cannot find answer to this - how to print number using Hebrew letters?

I've tried to change app language and/or using format provider:

myTextBox.Text = 555.ToString(new System.Globalization.CultureInfo("he-IL"));

but I can't get Hebrew letters.

like image 920
Romasz Avatar asked Oct 24 '25 04:10

Romasz


1 Answers

As Zohar says, in most uses Hebrew uses the same Indo-Arabic digits as English. If you really do want to write out a number using Hebrew letters though, a simple approach is:

public static string FormatHebrew(this int num)
{
  if(num <= 0)
    throw new ArgumentOutOfRangeException();
  StringBuilder ret = new StringBuilder(new string ('ת', num / 400));
  num %= 400;
  if(num >= 100)
  {
    ret.Append("קרש"[num / 100 - 1]);
    num %= 100;
  }
  switch(num)
  {
    // Avoid letter combinations from the Tetragrammaton
    case 16:
      ret.Append("טז");
      break;
    case 15:
      ret.Append("טו");
      break;
    default:
      if (num >= 10)
      {
        ret.Append("כלמנסעפצי"[num / 10 - 1]);
        num %= 10;
      }
      if(num > 0)
        ret.Append ("אבגדהוזחט" [num - 1]);
        break;
  }
  return ret.ToString ();
}

(Do make sure your text editor handles the ordering of the strings correctly, the main thing is that the source code as seen by the compiler has them in lower-to-higher order. A good text-editor will show that as right-to-left as that's the order Hebrew uses, but some will show it reversed from that).

like image 57
Jon Hanna Avatar answered Oct 25 '25 18:10

Jon Hanna



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!