//
        // Formats the electron configuration appropriately by finding the numbers that need to be converted to superscripts.
        //
        public static string formatElectronConfig(string config)
        {
            UnicodeConverter uni = new UnicodeConverter();

            string[] splittedConfig  = config.Split(',');
            string   formattedConfig = "";
            int      splitMarker     = 0;
            int      superNum;
            string   superStr;

            for (int i = 0; i < splittedConfig.Length; i++)
            {
                int configLen = splittedConfig[i].Length;

                for (int x = 0; x < configLen; x++)
                {
                    if (splittedConfig[i][x] == '^')
                    {
                        splitMarker = x;
                    }
                }

                for (int y = splitMarker; y < configLen - 1; y++)
                {
                    int.TryParse(splittedConfig[i][y + 1].ToString(), out superNum);
                    superStr          = uni.convertToSuperscript(superNum);
                    splittedConfig[i] = splittedConfig[i].Replace(splittedConfig[i][y].ToString(), superStr.ToString());
                }

                splittedConfig[i] = splittedConfig[i].Remove((configLen - 1), 1);
                formattedConfig  += splittedConfig[i];
            }

            return(formattedConfig);
        }
Example #2
0
        //
        // Converts the number of ions to a unicode subscript value.
        //
        public static string displayIonNumber(int n)
        {
            string           number;
            UnicodeConverter uni = new UnicodeConverter();

            if (n == 1)
            {
                number = "";
            }
            else
            {
                number = uni.convertToSubscript(n).ToString();
            }

            return(number);
        }
Example #3
0
        //
        // Formats the abbreviation of the ion to include subscripts.
        //
        public static string formatIonAbbr(string ionAbbr)
        {
            string           subNum;
            UnicodeConverter uni = new UnicodeConverter();

            for (int x = 0; x < ionAbbr.Length; x++)
            {
                for (int i = 0; i <= 9; i++)
                {
                    if (ionAbbr[x].ToString() == i.ToString())
                    {
                        subNum  = uni.convertToSubscript(i);
                        ionAbbr = ionAbbr.Replace(ionAbbr[x].ToString(), subNum);

                        if (x == ionAbbr.Length - 1)
                        {
                            ionAbbr = "(" + ionAbbr + ")";
                        }
                    }
                }
            }

            return(ionAbbr);
        }