I'm trying to extract a sequence of characters from a string in TCL.
Say, I have "blahABC:blahDEF:yadamsg=abcd"
.
I want to extract the substring starting with "msg="
until I reach the end of the string.
Or rather I am interested in extracting "abcd"
from the above example string.
Any help is greatly appreciated.
Thanks.
相关问题
- how to split a list into a given number of sub-lis
- Generate string from integer with arbitrary base i
- Converting a string array to a byte array
- How to convert a string to a byte array which is c
- format ’%s’ expects argument of type ’char *’
相关文章
- JSP String formatting Truncate
- Selecting only the first few characters in a strin
- Python: print in two columns
- extending c++ string member functions
- Google app engine datastore string encoding proble
- How to measure complexity of a string?
- What is the limit in size of a Php variable when s
- boost split with a single character or just one st
Another approach: split the query parameter using
&
as the separator, find the element starting with "msg=" and then get the text after the=
Code
Output:
update upvar not needed. see comments.
Regular expressions are the tools for these kind of tasks. The general syntax in Tcl is:
A simple solution for your task would be:
A nice tool to experiment and play with regexps ist Visual Regexp (http://laurent.riesterer.free.fr/regexp/). I'd recommend to download it and start playing.
The relevant man pages are re_syntax, regexp and regsub
Joachim