Solved

How do I extract a substring using tcl

Posted on 2006-07-10
3
5,705 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

635 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