TCL中的子串提取 [英] Substring extraction in TCL

查看:28
本文介绍了TCL中的子串提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 TCL 中的字符串中提取一系列字符.
比如说,我有 "blahABC:blahDEF:yadamsg=abcd".
我想提取以 "msg=" 开头的子字符串,直到到达字符串的末尾.
或者更确切地说,我对从上面的示例字符串中提取 "abcd" 感兴趣.
非常感谢任何帮助.
谢谢.

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.

推荐答案

另一种做法:以&为分隔符,对查询参数进行拆分,找到以"msg="开头的元素,然后得到=

Another approach: split the query parameter using & as the separator, find the element starting with "msg=" and then get the text after the =

% set string blahblah&msg=abcd&yada
blahblah&msg=abcd&yada
% lsearch -inline [split $string &] {msg=*}
msg=abcd
% string range [lsearch -inline [split $string &] {msg=*}] 4 end
abcd

这篇关于TCL中的子串提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆