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.

Tricky Database Question

Old posts that have not been replied to for several years.
Locked
S
SomeGuy
Voice
Posts: 13
Joined: Sat May 01, 2004 5:25 pm

Tricky Database Question

Post by SomeGuy »

Ok, say I have a line that looks like this:

name=char1,char2,char3,char4,

Now I have got my script to properly append new things on to that, as well as I have got it to list. Now where I get stuck is when I try to delete say char3, but leave everything else intact.

So say if I wanted to use a command to delete char 3, I want the line to in turn look like this:

name=char1,char2,char4,

I'm sure lreplace or append could do exactly what I lookin for here, but I'm such a newb when it comes to using lists. It took a long time just to get the adding and listing done.

If someone has a good link that may direct me on to how to do this that would be awesome. Or even just a push in the right direction, cuz i'm at a blank right now. Thanks
S
SomeGuy
Voice
Posts: 13
Joined: Sat May 01, 2004 5:25 pm

Post by SomeGuy »

Thanks to alot of searching, I found something that does just the job I need for this.

Code: Select all

proc varrep {string what with} { 
   if {![string match "*$what*" $string]} {return $string} 
   set cutstart [expr [string first $what $string] - 1] 
   set cutstop  [expr $cutstart + [string length $what] + 1] 
   set string [string range $string 0 $cutstart]$with[string range $string $cutstop end] 
   return $string 
} 
Then called with

set changed_var [varrep $string $what $with]

Having changed those var's of course ;p
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

In tcl, you can make lists with actual list commands rather than a string with entries separated by commas. It will be much easier to change stuff around. Then, if you need the comma-separated string for something later, you can use the join command to get it.

For instance:

set names
  • set string "names=[join $names ,]"

    now string = "names=name1,name2,name3,name4"
Locked