steelersfan 38 Posted November 15, 2016 Report Share Posted November 15, 2016 I am trying to check the characters within input on my bot, but the $text length parameter is counting new lines and spaces. How can I keep it from counting carriage returns and spaces? I tested this with a few simple tests, for example if I write a text file such as: 11 Just two one's, each on their own line, the carriage return gets counted and the length shown in the debugger is 3. If I write the words "1 plus 1" I get 8, if I write it again on a new line, I get 17. Sadly, this riddle took me an hour to figure out, but now I am just at a loss of how to compensate for this. Hopefully there is some workaround? For a while there, I thought "common core" got their hands on ubot and "educated" it in math, their way, lol! Quote Link to post Share on other sites
HelloInsomnia 1103 Posted November 15, 2016 Report Share Posted November 15, 2016 Use the $replace function, this can be nested, here is an example with and without it so you can see the difference: set(#text,"Enter your text here","Global") set(#length,$text length($replace($replace(#text," ",$nothing),$new line,$nothing)),"Global") alert("Text length: {#length} Without replacing: {$text length(#text)}") 1 Quote Link to post Share on other sites
Code Docta (Nick C.) 638 Posted November 15, 2016 Report Share Posted November 15, 2016 or you can prolly use $replace $newline with $nothing the python version set(#string to count,"This is some text to count and it should be awesome.","Global") alert($Character Counter(#string to count)) set(#string to count,"This is some text to count and it should be awesome.","Global") alert($Character Counter(#string to count)) define $Character Counter(#TEXT) { return($python result("","f_text = \'\'\'{#TEXT}\'\'\' len(f_text)")) } Regards,Nick 1 Quote Link to post Share on other sites
steelersfan 38 Posted November 16, 2016 Author Report Share Posted November 16, 2016 Awesome thanks guys! Quote Link to post Share on other sites
steelersfan 38 Posted November 16, 2016 Author Report Share Posted November 16, 2016 Use the $replace function, this can be nested, here is an example with and without it so you can see the difference: set(#text,"Enter your text here","Global") set(#length,$text length($replace($replace(#text," ",$nothing),$new line,$nothing)),"Global") alert("Text length: {#length} Without replacing: {$text length(#text)}") I can't see the non nested script, odd. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.