Solved

How do I extract a substring using tcl

Posted on 2006-07-10
3
5,693 Views
Last Modified: 2013-12-26
Hello, I need to extract a substring from another string using tcl.

I have tried using regexp without success.

Here is an example of what I need to do:

string1 = "22/OBGJ/123456_5.66:22/OBGJ/000123_7.134"

result

"22/OBGJ/123456_5.66"

I need to extract the entire substring upto but NOT including the ":" character.

Is there a simple solution for this?

Much thanks!
0
Comment
Question by:dongjinkim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Expert Comment

by:JJSmith
ID: 17077710

echo $string1 | cut -d":" -f1



cheers
JJ
0
 
LVL 3

Author Comment

by:dongjinkim
ID: 17077754
I should clarify that this is for tcl, not shell scripting.
I was not able to find a Tcl related channel, I apologize if this is not the best place to pose the question.
0
 
LVL 24

Accepted Solution

by:
slyong earned 500 total points
ID: 17078529

set x "22/OBGJ/123456_5.66:22/OBGJ/000123_7.134"   ;# This is your string
puts "[string range $x 0 [expr [string first ":" $x] - 1]]"        ;# [string first ":" $x] gives you the index of the first ":" and use [expr theposition - 1] to get the index - 1 position, then string range just extract out the substring
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question