INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Tcl: how to split string by blank lines

Tcl: how to split string by blank lines

(OP)
hello All,

could you please help me split a string into a list using as a delimiter a blank line ? split using "\n\n" doesn't seem to work. an example of such a string is the following :

Group: 1.1.1.1, (?)
Source: 2.2.2.2 (?)
Rate: 5382 pps/58470 kbps(1sec), 58469 kbps(last 30 secs), 58327 kbps(life avg)

Group: 3.3.3.3, (?)
Source: 4.4.4.4 (?)
Rate: 9150 pps/99399 kbps(1sec), 99398 kbps(last 30 secs), 85769 kbps(life avg)

Group: 5.5.5.5, (?)
Source: 6.6.6.6 (?)
Rate: 474 pps/5163 kbps(1sec), 5164 kbps(last 30 secs), 5144 kbps(life avg)

RE: Tcl: how to split string by blank lines

Hi there,
The split procedure will split by any of chars.
So practically [split $x "\n\n"] is the same as [split $x "\n\n"]

One idea will be to replace the "\n\n" sequence with a char that does not exists in your string a nd to use the split after.
E.g. "\x00" is a good one.
Let's assume that that in "x" variable you have your string.
Then to get the list that you want:
set list_x [split [string map [list "\n\n" "\x00"] $x] "\x00"]


Best Regards,
Marcel

___
http://www.notnull.ro/log
____

RE: Tcl: how to split string by blank lines

(OP)
thank you very much Marcel! it worked!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close