1

I have a string that I want to display a symbol in (the division symbol you learn in elementary, not a slash). According to the character map, the font that I'm using to display the string (inkpen2) has a division symbol code of 0xD4. I want a string to be "5 symbol 7" and display it to the user. Is it possible to do this?

2 Answers 2

10
string oneWay = "5 ÷ 7";
string anotherWay = "5 \u00F7 7";

Note that the first way can break if your source code ever has high bits stripped or is read by an app using some old text encodings. The second way is safer, just harder to read.

If you are using typographic math symbols, you may also want to use \u00D7 or × instead of *.

I don’t know where you get D4 from, but the Unicode value for the division symbol is F7, and C# uses unicode for all fonts.

5
  • 0xD4 is in a font called Inkpen2.
    – SLaks
    Aug 26, 2009 at 1:06
  • You could make it more readable by binding the unicode of the division symbol to a constant like const string DivisionSymbol = "\u00F7" and then doing something like string anotherWay = string.Format("5 {0} 7", DivisionSymbol);
    – cdmckay
    Aug 26, 2009 at 1:33
  • You could make it even more readable by embedding the Unicode character. I don't know of any reason not to.
    – SLaks
    Aug 26, 2009 at 1:40
  • 1
    @SLaks: Right, because everyone knows off the top of their head that \u00F7 means ÷.
    – cdmckay
    Aug 26, 2009 at 5:04
  • 1
    I think SLaks means to use ÷ instead of \u00F7. I added why that may be a bad idea. Aug 26, 2009 at 14:37
1

The beast way to do this is to use the standard Unicode code point instead of a custom font. In your case, you want U+00f7 ÷.

You can put that character in a string within your source code the same way you would use any other character, and it should work on almost any computer.


If you want to use a custom font, you can use the WinForms RichTextBox Control to display text with multiple fonts. If your entire string is in the same font, you can use a regular Label control and set its Font property. Note that you will need to distribute the font to your end-users, and that most fonts have license restrictions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.