functioncharge

Return the charge of a species given its chemical formula

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

Information

This function returns the net electrical charge associated with a species represented by a chemical formula (formula). If the charge number is not given explicitly in the formula, then it is assumed to be zero. A "+" or "-" without any immediately following digits is interpreted as a charge of +1 or -1, respectively. If there is an error in the chemical formula, then 0 is returned.

Example:
charge("Hg2+2") returns 2.

Inputs

TypeNameDefaultDescription
StringformulaChemical formula

Outputs

TypeNameDefaultDescription
IntegerzCharge number