如何确定字符串是否具有任何字母字符?
换句话说,如果字符串中只有空格,我该如何将其视为空字符串?
尝试:
if the_string.replace(" ", "") == "": the_string = ""
如果您的语言支持它,使用"trim","strip"或"chomp"来删除前导/尾随空格也可能是好的...
编辑:当然,正则表达式也可以解决这个问题:the_string.match("[^\s]")
...或自定义函数......或任何数量的东西.
编辑:在Caml:
let rec empty_or_space = fun [] -> true | (x::xs) -> x == ` ` and empty_or_space xs;;
编辑:根据要求,在LOLPYTHON中:
BTW OHAI SO IM LIKE EMPTY WIT S OK? LOL IZ S EMPTIE? DUZ IT HAZ UNWHITESPACE CHAREZ /LOL IZ S KINDA LIKE ""? U TAKE YEAH IZ S LOOK AT EASTERBUNNY OK KINDA NOT LIKE " "? U TAKE MEH U TAKE EMPTY WIT S OWN __getslice__ WIT CHEEZBURGER AND BIGNESS S OK OK