c# Cut String at Capital Letter -


i wanted make small program, have lot of doubles atom mass each atom. want able write molecule formula textbox, whereafter program should able calculate molar mass, however, dont know how can cut string textbox, instance can inserting "nacl" textbox, value of na double plus value of cl double.

namespace windowsformsapplication33 {     public partial class form1 : form     {         double h = 1.00794;         double = 4.002602;         double li = 6.941;         double = 9.012182;         ... 

these doubles, want button do:

        private void button1_click(object sender, eventargs e)         {             //take different atoms in molecule formula textbox,             //get value of doubles, , add them             //a final value, instance: nacl = na + cl = 22.98976928 + 35.453 = 58.44276928         } 

also, want able write h2so4, h*2 + s + o*4, how go doing that?

thank in advance

dictionary<string, double> chemicals = new dictionary<string, double>() { { "h", 1.00794 }, { "he", 4.002602 }, { "li", 6.941 }, { "be", 9.012182 } };         list<string> properties = new list<string>();          regex reg = new regex("[a-z]{1}[a-z0-9]*");         properties = reg.matches(txtinput.text).cast<match>().select(m => m.value).tolist();          double total = 0;         foreach (var property in properties)         {             var result = regex.match(property, @"\d+$").value;              int resultasint;             int.tryparse(result, out resultasint);              if (resultasint > 0)             {                 total += chemicals[property.substring(0, property.length - result.length)] * resultasint;             }             else             {                 total += chemicals[property];             }          }          lbloutput.text = "total: " + total.tostring(); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -