math symbols

How do I add math symbols when i write to a textile from vb.net eg like square root or superscript?
jagguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel WilsonCommented:
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.
0
abelCommented:
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
0
abelCommented:
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
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

abelCommented:
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
0
Daniel WilsonCommented:
Sorry, Abel.  I guess working with VB6 so long has me still thinking of Unicode as the exception rather than the rule.
0
abelCommented:
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

0
jagguyAuthor Commented:
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?
0
abelCommented:
ah, that's a whole different ballgame. I hate to remember the keyboard shortcuts (there are shortcuts for many of them, but not all), but the easy way to get this is to go to the Character Map of windows. Just click WinKey-R and then "charmap" + Enter (or any other method you like for starting Character Map) and select the symbols you like.

A hint: inside Character Map, you should select the Group By > Unicode Subrange and then Mathematical Symbols. Is the map empty? Select another font, which may have more glyphs.

A few shortcuts I found through that screen (the zero must be typed):

Superscript one: Alt+0185
Superscript two: Alt+0178
Superscript three: Alt-0179
Three Quarters: Alt+0190
Multiplication sign: Alt+215

Things like "Not equal to", "square root" etc are not giving their respective keyboard input, but you can calculate it yourself: just take the hexadecimal value (U+221A, bottom left in Charmap for square root) and make that decimal: 8730. Type Alt-8730 in any application in windows, and behold, there's the square root (if the selected font supports it).

Hmm, that's what it's supposed to be. But it isn't. It works in charmap and it works in other applications, but the corresponding codes are totally different. So, you're stuck with Charmap for now.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.