59 posts
Posted 21 February 2016 - 02:30 PM
Hi everyone,
I need your help…
I have this code
data = read()
if data == "" then
error
elseif fs.exists(data) then
stuff
else
error
end
How can I check if data is composed by a lot of spaces?
If data is " " then fs,exists() will not give any error messages and the code will crash below
Thanks you!
1426 posts
Location
Does anyone put something serious here?
Posted 21 February 2016 - 02:45 PM
You might want to look at
Lua patterns. %s can be used to represent any whitespace character and conversely %S can be used to represent any non-whitespace character. You can then use string.find to see if there is a non-whitespace character:
if data:find("%S") then
print(data)
else
error("Just whitespace")
end
Edited on 21 February 2016 - 01:46 PM
463 posts
Location
Star Wars
Posted 21 February 2016 - 02:47 PM
With
fs.getSize(string path), can you check the Size of the file.
59 posts
Posted 21 February 2016 - 02:49 PM
You might want to look at
Lua patterns. %s can be used to represent any whitespace character and conversely %S can be used to represent any non-whitespace character. You can then use string.find to see if there is a non-whitespace character:
if data:find("%S") then
print(data)
else
error("Just whitespace")
end
Thanks you a lot!
463 posts
Location
Star Wars
Posted 21 February 2016 - 03:00 PM
You might want to look at
Lua patterns. %s can be used to represent any whitespace character and conversely %S can be used to represent any non-whitespace character. You can then use string.find to see if there is a non-whitespace character:
if data:find("%S") then
print(data)
else
error("Just whitespace")
end
I think "not find".
if not data:find("%S") then
print(data)
else
error("Just whitespace")
end
3057 posts
Location
United States of America
Posted 21 February 2016 - 04:05 PM
if not data:find("%S") then
print(data)
else
error("Just whitespace")
end
I think you're confusing %S with %s.
463 posts
Location
Star Wars
Posted 21 February 2016 - 05:49 PM
I think you're confusing %S with %s.
Oh :blink:/>
Edited on 21 February 2016 - 04:50 PM