TCL (Tool Command Language) Question:
Download Questions PDF

How to extract "information" from "ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb" in tcl using a single command?

Answers:

% set
a "ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb"
ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb
% set b [string trimleft $a "abc"]
informationabcaaaaaabbbbbbbccbb
% set c [string trimright $b "abc"]
information


OR..
% set output [string trimright [string trimleft
$a "abc"] "abc"]
information
%

set ch \\"ccccccccaaaaaaabbbbbaaaaainformationabcaaaabbbbcbbbb\\"
regexp \\"information\\" $ch ch
puts $ch

set a \\"ccccccccaaabbbbaaaabbinformationabcaaaaaabbbbbbbccbb\\"

foreach oper {trimright trimleft} {
set a [string $oper $a \\"abc\\"]
}
puts $a

Download TCL Interview Questions And Answers PDF

Previous QuestionNext Question
How increment a character? For example, I give a and I should get b?How to Swap 30 & 40 in IP address 192.30.40.1 using TCL script?