Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Basic Misc > Newbie question...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 1335 of 1586
Post > Topic >>

Newbie question: Joining lines

by david.williams@[EMAIL PROTECTED] (David Williams) Sep 19, 2007 at 09:48 PM

-> Given a plain text file containing: 
 
-> xxx 
-> xxx 
-> yyy 
-> zzz 
 
-> How do I achive this: 
 
-> xxxxxx 
-> yyy 
-> zzz 
 
-> In other words... so long as the next line, matches the previous line. 
-> join the duplicates, else wise. I'm not wanting to globally 
-> join similar lines, but only so long as the line above matches. 
 
-> Hope that makes sense. 
  
Sense, yes, but I don't think it's a complete description. What happens 
if there are three or more identical consecutive lines? Should they all 
be concatenated together, or should they just be put in pairs? 
  
Okay... Untested (and so far unwritten) code: 
  
open "something" for input as #1 
line input #1, last$ 
current$ = last$ 
do 
  line input #1, new$ 
  if new$ = last$ then 
    current$ = current$ + new$ 
  else 
    print current$ 
    current$ = new$ 
    last$ = new$ 
  end if 
loop until eof(1) 
print current$ 
close 1 
end 
  
I've just used "print" as the output. Of course, you could have another 
file and output to that instead. 
  
I think that would work, concatenating two, three, or more identical 
strings if they appear consecutively in the input file. If you want 
them to be in pairs, you'll have to do some fiddling. 
  
                           dow
 




 2 Posts in Topic:
Newbie question: Joining lines
david.williams@[EMAIL PRO  2007-09-19 21:48:42 
Re: Newbie question: Joining lines
"Michael S. Sanders&  2007-09-21 15:03:38 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:23:48 CDT 2008.