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 end of a string

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
NewzNZ
Halfop
Posts: 68
Joined: Thu Mar 05, 2009 5:15 am
Contact:

removing end of a string

Post by NewzNZ »

Hi - I'm trying to get rid of the date/month/year on the end of these news headlines:

UK's Brown hopes Zimbabwe can rejoin Commonwealth 27 Nov 2009

At the moment I'm doing it by setting the 27 Nov 2009 part as a variable from another part of the webpage, and doing a string trimright to remove the variable. The problem then is, whenever a 27 or Nov or 2009 appears in the actual headline itself, it's trimming everything else with it:

eg.
African Markets - Factors to watch on Nov 27 27 Nov 2009
appears as just:
African Markets - Factors to watch on

any help to just lose the right-hand side date would be much appreciated!
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I suppose ome way around would be to use the string range command. You'd have to get the length of the strings first though (string length) and do some maths...

Not sure if string trimright would do the trick either?
NML_375
User avatar
NewzNZ
Halfop
Posts: 68
Joined: Thu Mar 05, 2009 5:15 am
Contact:

Post by NewzNZ »

thanks for those ideas nml375...

I actually got it working using regexp by putting the data variable at the end...should have thought of it earlier!

thanks again =)
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

eg.
African Markets - Factors to watch on Nov 27 27 Nov 2009
appears as just:
African Markets - Factors to watch on
If it's always 3 space separated elements at the end you want omitted. You can use join, lrange and split to do it as well, assuming $text is our string.

set text [join [lrange [split $text] 0 end-3]]
<speechles> .tcl set text "African Markets - Factors to watch on Nov 27 27 Nov 2009"
<bot> Tcl: African Markets - Factors to watch on Nov 27 27 Nov 2009
<speechles> .tcl set text [join [lrange [split $text] 0 end-3]]
<bot> Tcl: African Markets - Factors to watch on Nov 27
User avatar
NewzNZ
Halfop
Posts: 68
Joined: Thu Mar 05, 2009 5:15 am
Contact:

Post by NewzNZ »

ah yep thanks speechles...that's cool. it's like the '$mid' use in mIRC scripting that I was looking for.

thanks also!
Post Reply