String doesent want to become a number for some reason, Help me pls: D

How to I convert string to number? I cannot do int(MyWIndowsString) if you know what I mean…

bumo any body i dont want to use a for …

If there’s no way to convert a string directly to an int, then you probably will have to parse the string yourself one character at a time. I’m not going to test this myself, but I think you’ll want a function like this:

function int StringToInt(string InputString)
{
    local int i;
    local int OutputInt;
    for(i=0; i<len(InputString); i++)
    {
        OutputInt += (10 ** i) * CharToInt(mid(InputString, len(InputString) - i, 1));
    }
    return OutputInt;
}

function int CharToInt(string InputChar)
{
    switch(InputChar)
    {
        case "0":
            return 0;
        case "1":
            return 1;
        case "2":
            return 2;
        ...
    }
}

That may or may not work and it probably has an off-by-one problem with the indexing or something, so try it at your own risk. But that’s what I would do.

thanks Ill copy paste that :D.

I cast strings to ints just fine using Int(MyStringVar). No need for the long solution proposed above.

What compile errors are you getting? Or is the result not returning correctly during runtime?

What? for me it only gets the first letter out of a string.

Can you provide an example?

An example that i’ve just tested:

local String myString;

myString = "1001";

`log(int(myString) + 1);

Will log 1002.

Remember that Unrealscript uses 32bit integers, so its limits are between -2147483648 to 2147483647,.

Ok I will check that…

Emmmmh it is kind off my fault as the string is 1 1 1 1 instead of 1111

I was using @ to append a string while it was $ the best to do so else you get a space " " so i fixed it…