functionreadElement

Return the symbol, coefficient, and charge of an element in a chemical formula

Extends from Modelica.Icons.Function (Icon for functions).

Information

This function returns the symbol (symbol), stoichiometric coefficient (n), and electrical charge (z) associated with an element as it appears in a chemical formula (formula). After any initial whitespace in the formula string, which is ignored, the symbol must begin with a letter and may continue with lowercase letters. The symbol may be followed by a positive integer and then a charge number (both independently optional). If present, the charge number must begin with "+" or "-" and may be followed by optional digits. The remainder output gives the remainder of the formula string after the symbol, coefficient, and charge have been extracted.

If the coefficient is not explicitly given, then it is assumed to be one. If the charge number is not given, then it is assumed to be zero. A "+" or "-" without following digits is interpreted as a charge of +1 or -1, respectively. If there is an error, then symbol will be an empty string.

Example:
(symbol, n, z, remainder) = readElement("Hg2+2") returns symbol="Hg", n=2, z=2, and remainder="".

Inputs

TypeNameDefaultDescription
StringformulaChemical formula

Outputs

TypeNameDefaultDescription
StringsymbolName of element (empty if error)
IntegernStoichiometric coefficient
IntegerzCharge number
StringremainderRemainder of the chemical formula