// // Formats the abbreviation of the ion to include subscripts. // public static string formatabbr(string abbr) { string subNum; SmallNumber uni = new SmallNumber(); for (int x = 0; x < abbr.Length; x++) { for (int i = 0; i <= 9; i++) { if (abbr[x].ToString() == i.ToString()) { subNum = uni.convertToSubscript(i); abbr = abbr.Replace(abbr[x].ToString(), subNum); // Adding parentheses avoids confusion between polyatomic ions and the number of polyatomic ions needed to create the compound. if (x == abbr.Length - 1) { abbr = "(" + abbr + ")"; } } } } return(abbr); }
// // Converts the number of ions to a unicode subscript value. // public static string displayIonNumber(int n) { string number; SmallNumber uni = new SmallNumber(); if (n == 1) { number = ""; } else { number = uni.convertToSubscript(n).ToString(); } return(number); }
// // Formats the electron configuration appropriately by finding the numbers that need to be converted to superscripts. // Example of an electron configuration stored in the database: [Ar]3d^10,4s^2,4p^2 // public static string formatElectronConfig(string config) { SmallNumber uni = new SmallNumber(); // The configuration is split by each orbital. The "," separates each orbital. string[] splittedConfig = config.Split(','); string formattedConfig = ""; // These help determine which numbers are coefficients and which numbers are superscripts. int splitMarker = 0; int superNum; string superStr; for (int i = 0; i < splittedConfig.Length; i++) { int configLen = splittedConfig[i].Length; // Loops through an individual orbital configuration for (int x = 0; x < configLen; x++) { // The "^" indicates that the following character is a superscript. if (splittedConfig[i][x] == '^') { splitMarker = x; } } // This loops through the individual orbital configuration at the point where a character is the superscript. // The positions of electrons in an orbital is from 1-14, so double digits can occur and confuse superscripts and coefficients. for (int y = splitMarker; y < configLen - 1; y++) { int.TryParse(splittedConfig[i][y + 1].ToString(), out superNum); superStr = uni.convertToSuperscript(superNum); // This replaces the array element with the subscript number. splittedConfig[i] = splittedConfig[i].Replace(splittedConfig[i][y].ToString(), superStr.ToString()); } // This removes the last element of the array splittedConfig[i] = splittedConfig[i].Remove((configLen - 1), 1); formattedConfig += splittedConfig[i]; } return(formattedConfig); }