简体   繁体   中英

How to split a text(list) into sections(list) by a starting pattern in tcl

For example, my text is :

Block 1:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx
Block 2:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx
Block 3:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx

I want to split the by the different blocks, in tcl. Eg:

{Block 1:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx}
{Block 2:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx}
{Block 3:
   xxxxxx xxxx
   xxxxxx xxxx
   xxxxxx xxxx}

Any way to make this work? Thanks!

Try the tcllib `textutil::splitx`` command. (see http://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/textutil/textutil.html#8 )

It can split text based on a regular expression.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM