I'm working on a script that cuts up a long string of text into multiple posts so that no text is lost due to irc string restrictions. Now, the people i'm writing this for tend to use a lot of color codes, so I want my script to properly identify the last color code used before a specific point in this string and prepend it to the next string so it looks like a logical extention of the text instead of being all broken up.

Here's my current script so you can see what it does.

Code:
 on *:input:*: { 
  if ( ( $left($1,1) != / ) || ( $1 == /me ) ) {
    var %next     = <-next->
    var %continue = <-cont->
    var %done     = <-end->
    var %more     = <-more->
    var %textlen = $len($1-)
    if (%textlen > 400) {    
      var %pos = 1
      var %text = $mid($1-, %pos, 400)
      var %firsttime = 1
      while ( %text != $null ) {
        if ( $len($deltok(%text, -1, 32)) < 370 ) {
          %text = $left(%text, 370)
          inc %pos 370
        }
        else {
          %text = $deltok(%text,-1,32)
          inc %pos $len(%text)
          inc %pos
        }
        var %outtext = %text
        %text = $mid($1-, %pos, 400)
        if (%firsttime == 1) {
          if ($gettok(%outtext, 1, 32) == /me) {
            %outtext %next
          }
          else {
            say %outtext %next
          }
          %firsttime = 0;
        }
        else {
          if (%text != $null) {
            say %continue %outtext %next
          }
          else {
            if (%textlen <= 945) {
              say %continue %outtext %done
            }
            else {
              say %continue %outtext %more
            }
          }
        }
      }
      halt
    }
  }
} 


So now the question is, How do determine what was the last color code used, at the end of %outtext so I can prepend it to the next string being sent. Any ideas?

Rennir