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.

editing strings

Old posts that have not been replied to for several years.
Locked
s
sirkrunch
Voice
Posts: 19
Joined: Wed Oct 09, 2002 2:36 am

editing strings

Post by sirkrunch »

Hi,
i have a script that gets information from a file, but I dont want to display the last word, how can i go about cutting that last word out?

like mIRC could use the $gettok() using chr 32 (space) as the ident chr
there is only 2 spaces and its the last on that i want to remove, any help would be good

cheers
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

you can use lrange, for exampe

Code: Select all

lrange <string> 0 end-1
this will return the whole string except the last word.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

beeeeep!!!
you should NOT use list-commands on strings ;)
Elen sila lúmenn' omentielvo
H
Hal[PT]

Post by Hal[PT] »

You can use list commands if you are carefull with what you do. Using lindex directly on a string is just BAD. It freaks out with ; {} [] and can lead to security problems.

It can be solved with

Code: Select all

set tokens [split $mystring " "]
now you can use both lindex and lrange safely.

lindex $tokens N
returns word N (starting count from 0)
lrange $tokens start index end index
...

Nice and clean :P
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

how about

Code: Select all

join [lrange [split <string>] 0 end-1]
lol, it feels strange not being able to join the forum for 2 weeks or so and then come back for 5 mins just to take a look, as if all the experiance faded :P
Locked