Code: Select all
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"
	}
}
Code: Select all
% 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
Code: Select all
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"
   } 
}Channel:[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
Don`t why... from your example it should work.<Androo> BONUS +14:
<Androo> InmcemanmamavutmlocmprimamparticiparemamRomanieimlamunmturneumfinalmalmCampionatuluimMondialInmc
<Androo> 1st Hint: *** +12 Bonus
<Androo> 2nd Hint: d** +10 Bonus
<Androo> 3rd Hint: *aa +8 Bonus
Code: Select all
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]
}