Solved

How do I extract a substring using tcl

Posted on 2006-07-10
3
5,631 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
3 Comments
 
LVL 6

Expert Comment

by:JJSmith
Comment Utility

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



cheers
JJ
0
 
LVL 3

Author Comment

by:dongjinkim
Comment Utility
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
Comment Utility

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 57
sumDigits challenge 9 95
twoTwo  challenge 35 85
post4 challenge 28 81
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now