Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding blank lines

Status
Not open for further replies.

Loon

Programmer
May 24, 2000
100
GB
Hello again. <br><br>&nbsp;&nbsp;&nbsp;I've got a file full of text which I need to split up on blank lines, e.g. a \n at the begining of the line. Hence I have been using:<br><br><FONT FACE=monospace>while(&lt;INF&gt;)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (/^\n/)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#blank line code<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#code to handle other lines<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>}</font><br><br>I've also tried:<br><br><FONT FACE=monospace>@sections_of_text = split(/^\n/,$all_lines_of_text);</font><br><br>But neither seems to work, does the ^ need escaping within either of these expressions?<br><br>Many thanks for any help!<br>Loon
 
You're nearly there...&nbsp;&nbsp;Try changing the regexp so that it looks like:<br><FONT FACE=monospace><br>if (/^$/) {<br>...<br></font><br>In other words, look for lines with a beginning and an end, and nothing in between. :)<br> <p> <br><a href=mailto: > </a><br><a href= > </a><br>--<br>
0 1 - Just my two bits
 
Of course! I'm sure I read that just the other day somewhere... DOH!<br><br>Thanks for speedy response AndyBo!<br><br>Loon
 
You can use : <br>if ( /^$/ ) { <br>&nbsp;&nbsp;&nbsp;# hadle blank lines here <br>}<br>else {<br>&nbsp;&nbsp;&nbsp;# handle none blank lines here<br>}<br><br>* Remember : blank line is line with no white spaces in it. only newline <br>&nbsp;charavter ! <br>Alon <br><br><br>
 
/^\s*$/ would match non-blank lines with only whitespace characters<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top