Topic was automatically imported from the old Question2Answer platform.
Asked By
pferft
Hi everyone,
I have a label I can enter numbers into and I can detect if single numbers are in the text with (for each number respectively):
var oneIsWritten = false
var one = bbcode_text.find("1")
if one >= 1:
oneIsWritten = true
print ("There's a 1 in the text!")
(I can go the same way for “there's no 1 in the text” with "if one <= 0: …)
Now, if I’d like to know if there is actually any number between 1 and 9 written (explicitly leaving the 0 out), doing this with all the numbers true/false on their own would be too much handywork. I’m sure there is an elegant way of achieving this (maybe with an array…?)
for x in range(1,9) :
iff bbcode_text.find(str(x)) :
print ( "There is " + str(x) + " in the text" )
Thank you, so for 1 to 9 I’d need for x in range(1,10): then, I see.
It appears that in this case I always get nine line printed, one for each number, no matter which number I enter…
For getting the info if there is actually any number written or not, NatureSilver5401 on reddit suggests:
var writtennumbers = Array()
writtennumbers.append("whatever you like")
for number in 9:
if str(number+1) in text:
print("There is a " + str(number+1) + " in the text"
writtennumbers.append(true)
else:
writtennumbers.append(false)