static double GetPower(string strInp) { string str = strInp; PowerElements pow = GetPowerElements(str); double baseValue = 0; double exponentValue = 1.0; baseValue = Parse(pow.Base); exponentValue = Parse(pow.Exponent); return(Math.Pow(baseValue, exponentValue)); }
// method used in MtHtmlSupport as public public static PowerElements GetPowerElements(string powerString) { PowerElements p = new PowerElements(); string str = powerString; int firstIndexAfterPow = -1; if (str.Contains("pow")) { firstIndexAfterPow = str.IndexOf("pow") + "pow".Length; } if (str.Contains("Pow")) { firstIndexAfterPow = str.IndexOf("Pow") + "Pow".Length; } if (firstIndexAfterPow < 0 || firstIndexAfterPow >= str.Length) { return(p); } str = str.Substring(firstIndexAfterPow); str = GetOutBrackets(str); int separatorIndex = -1; int bracketLevel = 0; for (int i = 0; i < str.Length; i++) { if (str[i] == '(') { bracketLevel++; continue; } if (str[i] == ')') { bracketLevel--; continue; } if (str[i] == ',' && bracketLevel == 0) { separatorIndex = i; break; } } if (separatorIndex < 0) { return(p); } p.Base = str.Substring(0, separatorIndex); p.Exponent = str.Substring(separatorIndex + 1); return(p); }