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.

Hhelp with strip char

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

Hhelp with strip char

Post by whittinghamj »

Hi guys. when I am logging a line of text from #channel to logfile. How do I strip of the last charactor before writing the line to the logfile?

Some of my users have this dam annoying script which puts [ and ] start and end of every line they type.

Now I can miss out the first [ by lindex $text 1 end] and it works perfectly - just need to drop the VERY last char which happens to be a ] - as its logged in the file as \] - which is very annoying and very ugly.

Any help please --- I looked around the board for the strip syntax but I am either not really understanding it right or the posted did not seem line they would help any.

Thanks guys -

PS - its about time but I am writing my own darn script and not just requesting the full script this time he he - yay Quest
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

First off, don't ever use lrange (or lindex for that matter) in that fashion!
lrange is supposed to be used on lists, not plain text. What you should be using is 'string range' or possibly 'string strip'.

As for getting correct ranges for either lrange or string range, use end-1 as end-of-range argument to drop the last char (string range) or list item (lrange).

Manpage for 'string' can be found here
NML_375
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

Post by whittinghamj »

thank you so much for the tips - i am changing my script as needed.

One other question.

How do i take the spaces from the irc line and convert them into a period

eg

hello i am new here

would become in the log file

hello.i.am.new.here

any su8ggestions? point me in the right direction / have any sample code i can use as a base to work from please?
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

'string map' would probably be your friend here, assuming you've got tcl8.2 or later installed.

Code: Select all

string map [list " " "."] $string
If 'string map' is not available on your system, you could use regsub instead. Keep in mind that regular expressions can be abit "tricky" however...
NML_375
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Or you can use

Code: Select all

join [split $string] .
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

Post by whittinghamj »

hi guys

I am trying to use both of those examples but running into issues - no idea how to use them


here is what i have so fare

maybe u can see where i going wrong

Code: Select all

proc pub:addpreannounce {nick host hand chan arg} {
  global mysql
set pregroup [string range [lindex $arg 0] [expr {[string last - [lindex $arg 0]] + 1}] end ]
set rlstime [unixtime]
set string map [list " " "."] $arg
set rlsname [lindex $string 10]
set rlssection [lindex $arg 6]
there is some code after this but that part works fine

cheers
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

set string map [list " " "."] $arg

should be

set varname [string map {" " "."} $arg]


No clue what this is trying to accomplish:

set pregroup [string range [lindex $arg 0] [expr {[string last - [lindex $arg 0]] + 1}] end ]


Maybe try reading the manpages for 'string' and 'lindex' instead of just randomly mix-mashing these together like that.
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

Post by whittinghamj »

I got it thank you :D

I was not thinking right - been at this tcl for 9 hours non stop lol
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

sigh.

If we are truely supposed to be against helping people setting up things related to warez, why are we still helping them?
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

metroid wrote:sigh.
If we are truely supposed to be against helping people setting up things related to warez, why are we still helping them?
Guess I didn't think of it in that light.
Post Reply