|
Joined: Jan 2005
Posts: 75
Babel fish
|
OP
Babel fish
Joined: Jan 2005
Posts: 75 |
Is there a way to strip just background colours from text, and not the colour of the text itself?
|
|
|
|
Joined: Dec 2004
Posts: 81
Babel fish
|
Babel fish
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
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.
|
|
|
|
Joined: Jan 2005
Posts: 75
Babel fish
|
OP
Babel fish
Joined: Jan 2005
Posts: 75 |
what if there are multiple colour codes within the line of text?
|
|
|
|
Joined: Dec 2004
Posts: 81
Babel fish
|
Babel fish
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:
alias stripbg {
if ($pos($1-,$chr(3),0)) {
var %idx 0, %str $1-, %result, %num, %word
while (%idx < $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.
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
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 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.
|
|
|
|
Joined: Nov 2003
Posts: 2,327
Hoopy frood
|
Hoopy frood
Joined: Nov 2003
Posts: 2,327 |
Regex version: 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.
New username: hixxy
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
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 ) 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?)
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!
|
|
|
|
Joined: Nov 2003
Posts: 2,327
Hoopy frood
|
Hoopy frood
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
|
|
|
|
Joined: Jan 2005
Posts: 75
Babel fish
|
OP
Babel fish
Joined: Jan 2005
Posts: 75 |
Some great replies there, obviously the regex ones are out in front. thanks!
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
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.
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.
|
|
|
|
|