Check for empty text
An empty string has no characters. A space is still a character.
String.byte_length
Simple example
Is a string with no characters empty?
Start''
ResultTrue
def main() raises:
print(String("").byte_length() == 0)
True
Advertisements
Everyday examples
A library card has no name entered. Should the form ask for one?
Start''
ResultTrue
def main() raises:
print(String("").byte_length() == 0)
True
A passenger typed a space in the seat field. Is the raw field empty?
Start' '
ResultFalse
def main() raises:
print(String(" ").byte_length() == 0)
False
The classroom screen says Ready. Is the message empty?
Start'Ready'
ResultFalse
def main() raises:
print(String("Ready").byte_length() == 0)
False