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 (using a specific part of a string?)

Help for those learning Tcl or writing their own scripts.
Post Reply
b
br00
Voice
Posts: 9
Joined: Mon Jun 19, 2006 8:09 am

string help (using a specific part of a string?)

Post by br00 »

what it is, i have a string that always contains the word 'Size', i want to use only that which comes befor that word and forget the rest... have done some searching but to no avail

ie:
blah blah blah etc. Size
i want to use just the 'blah blah blah etc' bit (which is different every time)

so... how to cut the string at 'Size'??
d
deadite66
Halfop
Posts: 74
Joined: Mon May 30, 2005 2:49 am
Location: Great Yarmouth, UK

Post by deadite66 »

this works for me, might be a better way though.

Code: Select all

set sline "blah blah blah etc. Size"
set oline [string range $sline 0 [expr [string first "Size" $sline] - 1]]
puts $oline
<- tcl newb
User avatar
SaPrOuZy
Halfop
Posts: 75
Joined: Wed Mar 24, 2004 7:38 am
Location: Lebanon

Post by SaPrOuZy »

u could use regexp:

Code: Select all

regsub -all -- $sline "Size.*" sline ""
but be away that in both my solution and deadite66's , if the bla bla contains the word Size it will be removed too.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

advise: there is also a 'string last' :)
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...
Post Reply