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.

String Help

Old posts that have not been replied to for several years.
Locked
E
Esoteric
Voice
Posts: 19
Joined: Mon Apr 11, 2005 1:08 pm

String Help

Post by Esoteric »

I have a string that is in this format

username :: username :: username :: username ::

I need to output this as a single line in my channel but I don't want the first two to ever appear in the output.

Can anyone help?

Thanks!
-Erik
-Erik
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

Code: Select all

lrange [join [split $string ::]] 2 end
E
Esoteric
Voice
Posts: 19
Joined: Mon Apr 11, 2005 1:08 pm

Post by Esoteric »

how exactly to I then print that out?
-Erik
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

Code: Select all

bind pub - !parse parse:string
proc parse:string {nick uhost hand chan text} {
 set string "a :: b :: c :: d ::"
 set out [lrange [join [split $string ::]] 2 end]
 putserv "PRIVMSG $chan :$out"
}
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

PS: you cannot split on "::", the interpreter will threat it like ":", but because the empty elements are merged together with join again it won't bother as long USERNAME doesn't contain a ":".
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

hmm, good point, maybe something like this then..

Code: Select all

bind pub - !parse parse:string
proc parse:string {nick uhost hand chan text} {
 set string "a:b :: b :: c :: d ::"
 foreach s $string {
  if ![string match :: $s] {lappend out $s}
 }
 putserv "PRIVMSG $chan :[lrange $out 2 e]"

 # use this one if you want to keep the :: as a seperator
 # putserv "PRIVMSG $chan :[join [lrange $out 2 e] { :: }]"
}
E
Esoteric
Voice
Posts: 19
Joined: Mon Apr 11, 2005 1:08 pm

Post by Esoteric »

Alright one more question, now I need to make every other one a different color ... ie ...


blue :: red :: blue :: red :: blue :: red


etc..

Any ideas?
-Erik
E
Esoteric
Voice
Posts: 19
Joined: Mon Apr 11, 2005 1:08 pm

Post by Esoteric »

I haven't been able to find anything that will work ... can anyone help?
-Erik
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

Code: Select all

bind pub - !parse parse:string
proc parse:string {nick uhost hand chan text} {
 set string "a:b :: b :: c :: d ::"
 set type 0
 foreach s $string {
  if ![string match :: $s] {
   if !$type {
    lappend out \00302$s
    set type 1
   } {
    lappend out \00304$s
    set type 0
   }
  }
 }
 putserv "PRIVMSG $chan :[join [lrange $out 2 e] { :: }]"
}
E
Esoteric
Voice
Posts: 19
Joined: Mon Apr 11, 2005 1:08 pm

Post by Esoteric »

It doesn't work if the text has spaces ... for example:

firt last :: name :: last first :: name

The coloring gets jacked ... can you help?

Thanks!
-Erik
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

Code: Select all

bind pub - !parse parse:string
proc parse:string {nick uhost hand chan text} {
 set string "a:b :: b :: c :: d ::"
 set string [string map {"::" "~"} $string]
 set type 0
 foreach s [split $string ~] {
  if !$type {
   lappend out \00302$s
   set type 1
  } {
   lappend out \00304$s
   set type 0
  }
 }
 putserv "PRIVMSG $chan :[join [lrange $out 0 e] { :: }]"
}
Edit: fixed typo, thanks Sir_Fz !
Last edited by greenbear on Fri May 06, 2005 6:56 pm, edited 2 times in total.
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You will need to change

Code: Select all

set string [string map {"::" "~"] $string]
to

Code: Select all

set string [string map {"::" "~"} $string]
Edit: You're welcome gb :P
Last edited by Sir_Fz on Fri May 06, 2005 7:06 pm, edited 1 time in total.
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

oops, and this is why I shouldn't post code at 6am.. :oops:
Locked