Link to home
Start Free TrialLog in
Avatar of jagguy
jagguyFlag for Australia

asked on

math symbols

How do I add math symbols when i write to a textile from vb.net eg like square root or superscript?
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

Only ASCII values can be written to a text file.
http://www.asciitable.com/

If you're using Unicode, you can write Unicode characters.

But for math symbols you need a file format other than text.
There are different ways, if you want to go professional, you may want to look up MathML, but expect a learning curve. You say "text file", so I assume you just mean simple math symbols in between the text.

You can use Unicode for that, which is supported by Visual Basic, make sure that you open and write your file using Unicode (Encoding.UTF8 is fine), otherwise you will see a mangled effect or even errors.

Not all fonts support all the unicode characters. Here's a list of all mathematical symbols available: http://unicode.org/charts/PDF/U2200.pdf. In the screenshot you can see that my simple Arial font does not have many of that subset.

ScreenShot301.png
Note that when you write these symbols to a text file, someone opening it must understand UTF8. If you use Notepad, or actually Windows application, you should be fine (see attachment), which will automatically recognize it.

Sorry DanielWilson, but it is just not correct that only ASCII can be written to a text file, unless you have a very ancient system (70's, 80's like). In fact, many encodings and character sets exist, but for now, the most used and fully covering, well-supported encoding is Unicode, which is universally recognized.

-- Abel --



ScreenShot302.png
testMathematical.txt
So, back to the "how to". That's a piece of cake. If you use Visual Studio, by default, your files will be (should be!) in UTF8. You can test that by simply writing a line like the following (see screenshot) which I wrote in C# in Visual Studio.

Any character like that can be added. Even if the character cannot be represented because the font does not have that particular character, the character can still be used (you will see a block-like symbol). In that case, it is often better and more understandable, to use the codepoint instead.

ScreenShot303.png
Sorry, Abel.  I guess working with VB6 so long has me still thinking of Unicode as the exception rather than the rule.
understandable. Though even VB6, with a little work, could deal with Unicode (ChrW, AscW etc). Did you know that Windows used Unicode under the hood since, iirc, NT 3.51? And that the consumer edition has it since Windows 95/98, though partially, and that Win2K and XP have it fully and solely (meaning, it is not possible NOT to use it)?

Still many systems exist with mixed encodings. E-E for one, is completely Unicode, but has a problem in the backend, where it stores the data as ISO-8859-1 (how I know? Try to write some Unicode-aware characters, like the euro-sign. Though the page is served in Unicode, it won't come up as a euro sign).

To the OP, and more on the subject: to go from a codepoint to a character, you can use:



' these numbers can be found at unicode.org or any other online ref '
Dim cSummationSign As Char = Char.ConvertFromUtf32(&h2211)
Dim cSquareRoot As Char = Char.ConvertFromUtf32(&h221A)

Open in new window

Avatar of jagguy

ASKER

ok thanks for the replies as I didnt expect so many.
I am using vb.net express 2008. I am writing to a textfile and to write a math symbol like 'Abe'l' did I need , what do you press on the keyboard to make these symbols appear?
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial