egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Spliting text in two lines

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sun Jan 20, 2019 11:36 am    Post subject: Spliting text in two lines Reply with quote

Evening, can anyone help me with a code that will split the text in two lines (getting all the text in does 2 lines) if its bigger than a max length ? Thanks
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3583
Location: Mint Factory

PostPosted: Sun Jan 20, 2019 2:36 pm    Post subject: Reply with quote

In PHP there's a function called wordwrap that dose this nicely. Here's how I got about the same results in TCL.
Code:

proc wordwrap {text max} {
   set len [string length $text]
   while {$len} {
      if {$len > $max} {
         set cut [string range $text 0 [expr $max - 1]]
         set output [string range $cut 0 [string last " " $cut]]
         set text [string range $text [string length $output] end]
         incr len -$max
      } else {
         set output [string range $text 0 $len]
         set len 0
      }
      puts "output: $output"
   }
}

results:
Code:

% set text "Evening, can anyone help me with a code that will split the text in two lines (getting all the text in does 2 lines) if its bigger than a max length ? Thanks"
Evening, can anyone help me with a code that will split the text in two lines (getting all the text in does 2 lines) if its bigger than a max length ? Thanks
% wordwrap $text 80
output: Evening, can anyone help me with a code that will split the text in two lines
output: (getting all the text in does 2 lines) if its bigger than a max length ? Thank
% wordwrap $text 50
output: Evening, can anyone help me with a code that will
output: split the text in two lines (getting all the text
output: in does 2 lines) if its bigger than a max length
output: ? Thanks
% wordwrap $text 100
output: Evening, can anyone help me with a code that will split the text in two lines (getting all the text
output: in does 2 lines) if its bigger than a max length ? Thanks

Notice that it doesn't break words so it looks nicely.

PS: The code at the end of the Character hiding and showing topic isn't working or completly forgot about that topic? Rolling Eyes

PS #2: On Rosetta Code there's wrapParagraph with another approach on this.
_________________
I tawt I taw a puddy tat!
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Mon Jan 21, 2019 1:10 pm    Post subject: Reply with quote

Code:
proc Trivia247:wraptext {chan text characters} {
   
   set len [string length $text]
   putlog $len
 
   while {$len} {
      if {$len > $characters} {
         set cut [string range $text 0 [expr $characters - 1]]
         set output [string range $cut 0 [string last " " $cut]]
         set text [string range $text [string length $output] end]
         incr len -$characters
      } else {
         set output [string range $text 0 $len]
         set len 0
      }
      putlog "$output"
      putlog "[string length $output]"
      
      putserv "PRIVMSG $chan :$output"
   }
}



DCC CHAT:

Quote:
[18:09:03] 1499
[18:09:03] BONUS +14:
[18:09:03] 44

[18:09:03] 0

[18:09:03] 0
[18:09:03] InmcemanmamavutmlocmprimamparticiparemamRomanieimlamunmturneumfinalmalmCampionatuluimMondialInmc
[18:09:03] 300


Channel:
Quote:
<Androo> BONUS +14:
<Androo> InmcemanmamavutmlocmprimamparticiparemamRomanieimlamunmturneumfinalmalmCampionatuluimMondialInmc
<Androo> 1st Hint: *** +12 Bonus
<Androo> 2nd Hint: d** +10 Bonus
<Androo> 3rd Hint: *aa +8 Bonus


Don`t why... from your example it should work.
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 602
Location: Tennessee, USA

PostPosted: Tue Jan 22, 2019 1:34 am    Post subject: Reply with quote

That script tries to split the text in a correct place, at the nearest space.

The string you try is long, but has no spaces.

That is not a valid string, there is no single "word" that long:)
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
heartbroken
Halfop


Joined: 23 Jun 2011
Posts: 93
Location: somewhere out there

PostPosted: Tue Jan 22, 2019 12:16 pm    Post subject: Reply with quote

tcllib/textutil could be an alternative: https://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/textutil/textutil_split.html
_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Wed Jan 23, 2019 2:42 pm    Post subject: Reply with quote

It looks that way because of the ANTI HACK part.
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Wed Jan 23, 2019 3:05 pm    Post subject: Reply with quote

heartbroken: Works only if i stop the antihack part. So when the questions is "word word word" works, but when its in a single word it brocks.

Anyone with an idea on how to make anything split using the antihack option?

Antihack = it adds a random letter each question between the spaces of the words, so if you try to copy - paste the question it would be "impossible" to read.
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3583
Location: Mint Factory

PostPosted: Thu Jan 24, 2019 3:40 am    Post subject: Reply with quote

Basically the line you are mentioned is most likely from a trivia bot and is "obfuscated" by adding a character between words and a special color so that regular legit users can see the question without the extra colored characters, but anyone else why tries to be cheeky or copy/paste the question would have a hard time "decoding" it back to a normal question.

If you own the bot (based on your claim that you can start/stop the "obfuscation" process) that is spitting the trivia questions why do you need this? What exactly do you want to achieve here? Want to cheat at your own game? Laughing

Since the "special" character used to "obfuscate" the code (in the given example is "m") is also found in the other words used in the question reversing the process is kind off an impossible task, unless you know exactly at what positions it was added. For example an extra 'm' is added at 2, 5, 8, and so on. So if you know the pattern then is easy to replace the special character with a space and then recreate the question into a "word word word" that with the code I mentioned would get the result you wanted.
_________________
I tawt I taw a puddy tat!
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Thu Jan 24, 2019 8:59 am    Post subject: Reply with quote

Yes its from a trivia script i wrote from scratch.

I was thinking of something to add the letters after the split, but never got it working.
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3583
Location: Mint Factory

PostPosted: Sun Jan 27, 2019 1:54 pm    Post subject: Reply with quote

As i was looking on the forums for something I stumbled onto a very old discussion (this) where user and strikelight (two forum users, long time idle sadly) debated over a pice of code user made to wrap some text output. Here is the final code with the changes they discussed:
Code:

proc wordwrap {str {len 70} {splitChr { }}} {
   set out [set cur {}]; set i 0
   foreach word [split [set str][set str ""] $splitChr] {
      if {[incr i [string len $word]]>$len} {
         lappend out [join $cur $splitChr]
         set cur [list $word]
         set i [string len $word]
      } else {
         lappend cur $word
      }
      incr i
   }
   lappend out [join $cur $splitChr]
}

_________________
I tawt I taw a puddy tat!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber