Jump to content
UBot Underground

Text Length, Counting New Lines And Spaces


Recommended Posts

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:

 

1

1

 

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!

Link to post
Share on other sites

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)}")
  • Like 1
Link to post
Share on other sites

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

  • Like 1
Link to post
Share on other sites

 

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...