Sciencemadness Discussion Board
Not logged in [Login - Register]
Go To Bottom

Printable Version  
 Pages:  1  2
Author: Subject: Two FREE tools you probably didn't even know you had!
Diachrynic
Harmless
*




Posts: 19
Registered: 23-9-2017
Location: Germany
Member Is Offline

Mood: existent

[*] posted on 1-10-2017 at 02:54
Make chemistry equations look different with Unicode


I made a small program (23 KB) to make chemical equations somewhat look better.

It turns this:

2MnO4 - + SO3 2- + 2OH- --> 2MnO4 2- + SO4 2- + H2O

into this:

2MnO₄⁻ + SO₃²⁻ + 2OH⁻ → 2MnO₄²⁻ + SO₄²⁻ + H₂O

by using a bunch of RegEx and Unicode. (Had to increase size a bit 'cause it was kind of small.)

If anyone wants to try it out, here is a download link: http://www.mediafire.com/file/aesa60r6c2w4e41/ChemistryInlin... (Just in case if the upload here does not work.)

If anyone wants to extend it, here is the important part of the source code (language is VB):

Code:
Private Sub Convert() Dim Str1 As String = TextBox1.Text Str1 = " " + Str1.TrimEnd(" ") Str1 = Regex.Replace(Str1, "[<]+[-‒–—―=]*[>]+", "↔") Str1 = Regex.Replace(Str1, "[-‒–—―=]*[>]+", "→") Str1 = Regex.Replace(Str1, "(?<!\s\d*)0(?!\d*[+-]+)", "₀") Str1 = Regex.Replace(Str1, "(?<!\s\d*)1(?!\d*[+-]+)", "₁") Str1 = Regex.Replace(Str1, "(?<!\s\d*)2(?!\d*[+-]+)", "₂") Str1 = Regex.Replace(Str1, "(?<!\s\d*)3(?!\d*[+-]+)", "₃") Str1 = Regex.Replace(Str1, "(?<!\s\d*)4(?!\d*[+-]+)", "₄") Str1 = Regex.Replace(Str1, "(?<!\s\d*)5(?!\d*[+-]+)", "₅") Str1 = Regex.Replace(Str1, "(?<!\s\d*)6(?!\d*[+-]+)", "₆") Str1 = Regex.Replace(Str1, "(?<!\s\d*)7(?!\d*[+-]+)", "₇") Str1 = Regex.Replace(Str1, "(?<!\s\d*)8(?!\d*[+-]+)", "₈") Str1 = Regex.Replace(Str1, "(?<!\s\d*)9(?!\d*[+-]+)", "₉") Str1 = Regex.Replace(Str1, "((?<=\s\d+)[+]|(?<=\s)[+](?=\s*[+-]+)|(?<=\s+)[+]$|(?<=[A-Za-z])[+])", "⁺") Str1 = Regex.Replace(Str1, "((?<=\s\d+)[-]|(?<=\s)[-](?=\s*[+-]+)|(?<=\s+)[-]$|(?<=[A-Za-z])[-])", "⁻") Str1 = Regex.Replace(Str1, "\s+0(?=[⁺⁻]+)", "⁰") Str1 = Regex.Replace(Str1, "\s+1(?=[⁺⁻]+)", "¹") Str1 = Regex.Replace(Str1, "\s+2(?=[⁺⁻]+)", "²") Str1 = Regex.Replace(Str1, "\s+3(?=[⁺⁻]+)", "³") Str1 = Regex.Replace(Str1, "\s+4(?=[⁺⁻]+)", "⁴") Str1 = Regex.Replace(Str1, "\s+5(?=[⁺⁻]+)", "⁵") Str1 = Regex.Replace(Str1, "\s+6(?=[⁺⁻]+)", "⁶") Str1 = Regex.Replace(Str1, "\s+7(?=[⁺⁻]+)", "⁷") Str1 = Regex.Replace(Str1, "\s+8(?=[⁺⁻]+)", "⁸") Str1 = Regex.Replace(Str1, "\s+9(?=[⁺⁻]+)", "⁹") Str1 = Regex.Replace(Str1, "\s+(?=[₀₁₂₃₄₅₆₇₈₉]*[⁺⁻])", "") TextBox2.Text = Str1.TrimStart(" ") End Sub


To anyone better in programming this probably looks horrible ;)

Have fun!

Cheers

Attachment: ChemistryInlineFormula.exe (23kB)
This file has been downloaded 19 times




Signature currently under construction. We apologize for the inconvenience.
Calling all. This is our last cry before our eternal silence.
View user's profile View All Posts By User
 Pages:  1  2

  Go To Top