Solved: Stupid Question: Integers

How do I convert a string into an integer? Within the string, the int is stored in hex, such as “0x2B”. This will occur in some 2da’s, such as spells.2da. “StringToInt” doesn’t work.

It’s no problem to write a short function to solve this, but I’m curious if there is a native function for the conversion.

There’s not native function, but you can use this:

int HexStringToInt(string sString)
{
    sString = GetStringLowerCase(sString);
    int nResult, nLength = GetStringLength(sString), i;

    for (i = nLength - 1; i >= 0; i--)
    {
        int n = FindSubString("0123456789abcdef", GetSubString(sString, i, 1));
        if (n == -1)
            return nResult;
        nResult |= n << ((nLength - i - 1) * 4);
    }
    return nResult;
}

That I wanted to know, thanks!