Page 1 of 1

Re: How to get only numbers from a string

Posted: Friday 16 August 2019 6:58
by EddyG
Use a split function with a space as delimiter.

Code: Select all

function split(s, delimiter)
    result = {};
    for match in (s..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, match);
    end
    return result;
end

Re: How to get only numbers from a string

Posted: Friday 16 August 2019 11:19
by MikeF
In Python, you can just do this (in your specific case):

Code: Select all

Data = parsedJson["result"][1]["Data"][:-4]
which will drop off the last 4 characters.

Re: How to get only numbers from a string

Posted: Friday 16 August 2019 12:24
by waaren

Steven29 wrote: How to get rid of the kWh ? So the outcome will be 2.700
Use

Code: Select all

print("Data:" .. Data:match('%d+'))
in Lua / dzVents