mIRC Home    About    Download    Register    News    Help

Print Thread
#109904 02/02/05 07:28 PM
Joined: Jan 2005
Posts: 75
Z
ztnaraM Offline OP
Babel fish
OP Offline
Babel fish
Z
Joined: Jan 2005
Posts: 75
Is there a way to strip just background colours from text, and not the colour of the text itself?

#109905 02/02/05 08:16 PM
Joined: Dec 2004
Posts: 81
N
Babel fish
Offline
Babel fish
N
Joined: Dec 2004
Posts: 81
A little something I came up with. I'm sure there's other ways to do this, but here's mine smile

Code:
alias stripbg {
  if ($left($1,1) == $chr(3)) {
    var %num1, %num2
    %num1 = $remove($gettok($1-,1,44),$chr(3))
    %num2 = $left($gettok($1-,2,44),2)
    if ($right(%num2,1) isletter) { %num2 = $left(%num2,1) }
    if ((%num1) && (%num2)) {
      return $+($chr(3),%num1,$strip($1-))
    }
  }
}


Usage:

$stripbg(<text>)

NOTE:

A background color must be present within the text or this won't work.

Last edited by nycdiesel; 02/02/05 08:17 PM.
#109906 02/02/05 09:13 PM
Joined: Jan 2005
Posts: 75
Z
ztnaraM Offline OP
Babel fish
OP Offline
Babel fish
Z
Joined: Jan 2005
Posts: 75
what if there are multiple colour codes within the line of text?

#109907 02/02/05 09:20 PM
Joined: Dec 2004
Posts: 81
N
Babel fish
Offline
Babel fish
N
Joined: Dec 2004
Posts: 81
heh, i didnt think that one through, lol. let me see what i can come up with.

here's what i've come up with:

Code:
alias stripbg {
  if ($pos($1-,$chr(3),0)) {
    var %idx 0, %str $1-, %result, %num, %word
    while (%idx &lt; $numtok(%str,32)) {
      inc %idx
      %word = $gettok(%str,%idx,32)
      if ($left(%word,1) == $chr(3)) {
        %num = $gettok($remove($mid(%word,1,6),$chr(3)),1,44)
        %result = %result $+($chr(3),%num,$strip(%word))
      }
      else { %result = %result $strip(%word) }
    }
    return %result
  }
}

Last edited by nycdiesel; 02/02/05 10:11 PM.
#109908 02/02/05 10:24 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
alias stripbg {
  var %text = $1-
  var %i = $pos(%text,$chr(3),0)
  while (%i) {
    ;^ loop through all the ctrl-k's
    ;
    var %l = $pos(%text,$chr(3),%i)
    inc %l
    ;^ move to first character following ctrl-k
    ;
    if ($mid(%text,%l,1) isnum) {
      inc %l
      ;^ if its a number move past it
      ;
      if ($mid(%text,%l,1) isnum) { inc %l }
      ;^ possable second number, if so move past it
      ;
      if ($mid(%text,%l,1) == $chr(44)) {
        var %pre = %l
        inc %l
        ;^ if next character is a , then store that possition as everything before a potential background color, then move past it
        ;
        if ($mid(%text,%l,1) isnum) {
          inc %l
          ;^ if its a number move past it
          ;
          if ($mid(%text,%l,1) isnum) {
            inc %l
            ;^ possable second number, if so move past it
            ;
          }
          var %post = %l
          var %text = $+($left(%text,%pre),99,$mid(%text,%post))
          ;^ Therewas a background color and we have the position PREcedding it, and POST it so replace it with 99 being an invalid background color.
          ;
        }
      }
    }
    dec %i
    ;^ move to next ctrl-k
    ;
  }
  return %text
  ;^ return result
  ;
}


I cut that out from something else I had, and tested it, it appears to work, but might have a fault in it, if it doesnt dump a bg color one day, well sorry smile

I added the comments in here, incase someone couldnt follow (or wanted to)

Im sure a nice regex would matchup whats wanted with less if's but what the heck, i suck at regex so i didnt do one.

#109909 02/02/05 10:50 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
Regex version:

Code:
alias stripbg {
  var %a, %b = $regsub($$1,/(\03\d+)\54\d+/g,\1,%a)
  return %a
}


//var %c = 7,15lol | echo -a $stripbg(%c)

The reason I used a variable is because , is a token delimiter in an identifier. smile


New username: hixxy
#109910 03/02/05 01:44 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
Code:
alias stripbg {
  var %a, %b = $regsub($$1,/(\03\d+)\54\d+/g,\1,%a)
  return %a
}


hmmm the 54 stumped me for a bit tell i releasied it was octal

I assume the \1 is a "back refrence" (i had to look that up smile ) to the (\03\d+)

Can i suggest this , although its incomplete becuase for the life of me i cant work out how to get the 99 in there.
Where there are two X's i need that replaced with 99 but that makes a \199 which isnt whats wanted, and i cant work out how to do that bit. (any help please?)
Code:
alias stripbg {
  var %a, %b = $regsub($$1,/(\03\d\d?\54)\d\d?/g,\1XX,%a)
  return %a
}



The reason im saying this is coloring is limited to 6 patterns [ <ctrl-k># <ctrl-k>## <ctrl-k>#,# <ctrl-k>#,## <ctrl-k>##,# <ctrl-k>##,## ] anything else becomes text also removing the background color if located can cause following text to become that background color if that text happened to start with ,# or ,##

examples
msg $chan Only add the ,number if you selected centerpeed and u want to say how many legs it should have !creature centerpeed<ctrl-k>7,12,14 for 14 legs
this would before have translated to
Only add the ,number if you selected centerpeed and u want to say how many legs it should have !creature centerpeed<ctrl-k>7,14 for 14 legs
making background color 14

if the above one can be made to put 99 in there as in
Only add the ,number if you selected centerpeed and u want to say how many legs it should have !creature centerpeed<ctrl-k>7,99,14 for 14 legs
Then the background color is ignored as its invalid.

PS: Damn regex's are good value! Double Damn i suck at them!

#109911 03/02/05 04:04 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
\d\d? would be better than \d+ actually, so that you can't enter things like ^K10320.

I can't think of a way to do the \1XX at the moment, sorry.


New username: hixxy
#109912 03/02/05 04:20 PM
Joined: Jan 2005
Posts: 75
Z
ztnaraM Offline OP
Babel fish
OP Offline
Babel fish
Z
Joined: Jan 2005
Posts: 75
Some great replies there, obviously the regex ones are out in front. thanks! laugh

#109913 03/02/05 11:49 PM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I couldnt stand that i couldnt get the 99 in there, so i kludged a patch in.

I put in two bolds in, then extract them using a replace.

Code:
alias stripbg {
  var %a, %b = $regsub($$1,/(\03\d\d?\54)\d\d?/g,\199,%a)
  return $replace(%a,$chr(44) $+ 99,$chr(44) $+ 99)
}


Note : the  character if it doesnt come through is ctrl-b

PS: anyone who says i could just use a $remove(%a,), well u could but that might be in the line already for some specific reason (i infact use them to mark hotlink spots), the chance of a ,99 being in the line already is pretty unlikely tho.


Link Copied to Clipboard