This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Removing colors etc from string.

Old posts that have not been replied to for several years.
Locked
B
Benpsycho

Removing colors etc from string.

Post by Benpsycho »

Hi, I want to parse the text of someone and put this into a mysql database. I found this function to remove colors from the post:

Code: Select all

# mirc_strip [switches] <text>
#     version:
#       v1.0
proc mc:sc:mirc_strip {{args ""}} {
  mc:sc:badargs $args 1 7 "?switches? text"
  set switches ""
  for {set i 0} {[string match -* [set arg [lindex $args $i]]]} {incr i} {
    if {![regexp -- {^-(all|bold|color|reverse|underline|-)$} $arg -> switch]} {
      set valid "-all -bold -color -reverse -underline {or --}"
      error "bad switch \"$arg\": must be [join $valid ", "]"
    }
    if {$switch == "-"} {
      incr i
      break
    }; lappend switches $switch
  }
  if {$switches == ""} {set switches all}
  set arg [lindex $args $i]
  mc:sc:badargs [lrange $args $i end] 1 1 "?switches? text"

  set all [expr {([lsearch -exact $switches all] >= 0) ? 1 : 0}]
  set list ""
  if {$all} {
    set list [list \002 "" \017 "" \026 "" \037 ""]
  } else {
    if {[lsearch -exact $switches bold] >= 0} {lappend list [list \002 ""]}
    if {[lsearch -exact $switches plain] >= 0} {lappend list [list \017 ""]}
    if {[lsearch -exact $switches reverse] >= 0} {lappend list [list \026 ""]}
    if {[lsearch -exact $switches underline] >= 0} {lappend list [list \037 ""]}
  }
  if {$all || ([lsearch -exact $switches color] >= 0)} {
    regsub -all -- "\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?" $arg "" arg
  }
  set arg [mc:sc:replace -- $arg [join $list]]

  return $arg
}

But when I put the text into a mysql datbase some strings still have a in them. Could someone help me with this? What did I forget to remove form the string?

Thx alot!
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

I don't think is a color, is it? If not, why would a color stripper remove it?

Why don't you post some sample lines that cause that error.
B
Benpsycho

Post by Benpsycho »

Ok, this is the mirc code:

Code: Select all

2[14P-R-E2] 2[12MP31/121REAL2] 2[Jay_Epoch-Particles-Directions_In_Groove_(Proton)_28-03-2004-1REAL2]
This is how it looks:
Image
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: Removing colors etc from string.

Post by user »

Benpsycho wrote:when I put the text into a mysql datbase some strings still have a in them. Could someone help me with this? What did I forget to remove form the string?
That "" is the mIRC control code for plain text. I think the proc you pasted is a bit overkill if you want to strip all control codes. Try this instead:

Code: Select all

proc mircstrip text {
	regsub -all {\002|\003([0-9]{1,2}(,[0-9]{1,2})?)?|\017|\026|\037} $text {} text
	set text
}
stdragon wrote:I don't think is a color, is it?
you're right. :P
Have you ever read "The Manual"?
B
Benpsycho

Post by Benpsycho »

That worked fine! Thx!
Locked