Jump to content
  • 0

how to count length of a string starting from the decimal separator


Platonic

Question

Posted

Having some issue. This issue is basically from a topic which has been mentioned before but it seemed for the best to create a new topic. Just in case if you need old topic for follow up with new one. But script has by now been improved based on current knowledge obtained.

The script is supposed to count the length of the string. And if the condition is met it has to put the sub table in to the new table named "firstTable"

a = gg.getResults(4)
firstTable = {}
for k, t in pairs(a) do
if string.len(t.value) <= 6 then
firstTable[#firstTable + 1] = t
end
end
print("firstTable: ", firstTable)

It does work as you can see in the screenshot but not really as accurate as i want to. It returns the entire length of the string but i need it to return the length of the string starting from the decimal separator so that i can place a more appropriated condition on the key values.

Schermafbeelding 2022-04-05 133451.png

3 answers to this question

Recommended Posts

Posted
yourvalue = 12.3456
yourvalue = tostring(yourvalue):gsub("^%d+%.",'')

print( 'Yourvalue = '..yourvalue )
print( 'String length is '..string.len(yourvalue) )

 

Posted
6 hours ago, MarioRossi93i said:
yourvalue = 12.3456
yourvalue = tostring(yourvalue):gsub("^%d+%.",'')

print( 'Yourvalue = '..yourvalue )
print( 'String length is '..string.len(yourvalue) )

 

Thanks, working great!
 

a = gg.getResults(4)

firstTable = {}
for k, t in pairs(a) do
valueSub = tostring(t.value):gsub("^%d+%.", '')
if string.len(valueSub) <= 6 then
firstTable[#firstTable + 1] = t
end
end
value = gg.loadResults(firstTable)
print()
print("firstTable: ", firstTable)

 

Schermafbeelding 2022-04-05 232430.png

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.