INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

substring in TCL

substring in TCL

(OP)
Hi

Is there an easy way to perform substring operations in TCL

For eg if I have a file with something like

# Ingore this
#ignore
a1:a2:a3
b1:b2:b3

And
1. I want to ignore the lines with #
2. I want to pick each value between the ':' for each line and assign them to different variables
i.e. set var1 = a1
set var2 = a2
set var3 = a3
....etc
 within a loop for every line

Is this possible

RE: substring in TCL

Hi

Quote (birdy1980):

Is there an easy way to perform substring operations in TCL
string range

As requested, however I would skip the part with the separate var1..var3 variables :

CODE --> Tcl

set file [open "birdy1980.txt"]

while {[gets $file line]!=-1} {
  if {[string range $line 0 0]=="#"} { continue }
  set part [split $line ":"]
  set var1 [lindex $part 0]
  set var2 [lindex $part 1]
  set var3 [lindex $part 2]
}

close $file
 

Feherke.

RE: substring in TCL

(OP)
Hi Feherke

That was quick! wow.

The reason for setting to different variables is because we are planning to read a file which has such a format to get details of parameters which will be used in the script.
That was the only reason.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close