/// <summary> /// Trim the 0x, x, 0X, or X from the beginning of the string if needed so the hex parse to a number will work /// </summary> /// <param name="s"></param> public static void HexParsePrep(ref string s) { s = StringEx.UserText(s); if (s != null && s.Length >= 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) { s = StringEx.UserText(s.Substring(2)); } }
public static bool?GetBool(object val, bool parse) { if (val == null) { return(null); } try { TypeCode tc = val.GetTypeCode(); switch (tc) { case TypeCode.String: if (!parse) { return(null); } bool n; string s = StringEx.UserText(val as string); if (s == null) { return(null); } if (TryFromServer(s, out n, false)) { return(n); } switch (s[0]) { case 'T': case 't': case '1': return(true); case 'F': case 'f': case '0': return(false); default: return(null); } default: if (IsNumeric(tc)) { return(Convert.ToBoolean(val)); } byte[] b = val as byte[]; int ix = 0; if (b?.Length == sizeof(bool)) { return(IOEx.GetBool(b, ref ix)); } return(null); } } catch { return(null); } }
public static int[] TryToInts(this string ids, char sep = StringEx.c_sep) { return(TryToInts(StringEx.UserText(ids)?.Split(sep)?.Select(z => z?.Trim()))); }
/// <summary> /// IXmlSerializable implementation to export the key as a numeric string content /// </summary> public void ReadXml(XmlReader reader) { reader.MoveToContent(); Str = StringEx.UserText(reader.ReadElementContentAsString()); }