Normal Topic Combine two text files (Read 737 times)
CapitalG
Full Member
Members
***
Offline



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
Combine two text files
Dec 12th, 2006 at 9:56pm
Print Post Print Post  
If I have two comma separated text files and each file is two lines - the first is a header line and the second is the data line, how do I combine those files in sbasic so that I end up with one file with the first line all the headers and the second line is the data?

example: file one is:   Name, Address
                                John, 123 any Street

              file two is:   Age, Gender
                                32, Male

Combined file to be: Name, Address, Age, Gender
                              John, 123 any Street, 32, Male



Thanks for your help.  Smiley
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Combine two text files
Reply #1 - Dec 13th, 2006 at 2:24am
Print Post Print Post  
Without niceties:

Code
Select All
var fh1 as int
var fh2 as int
var fh3 as int
var str1 as string
var str2 as string
var str3 as string

	fh1 = fileOpen("FileA.txt")
	fh2 = fileOpen("FileB.txt")
	fh3 = fileOpen("OutFile.txt")
	fileSeek(fh1, 0)
	fileSeek(fh2, 0)
	fileSeek(fh3, 0)
	fileReadln(fh1, str1)
	fileReadln(fh2, str2)
	str3 = str1 + ", " + str2
	fileWriteln(fh3, str3)

	fileReadln(fh1, str1)
	fileReadln(fh2, str2)
	str3 = str1 + ", " + str2
	fileWriteln(fh3, str3)

	fileClose(fh3)
	fileClose(fh2)
	fileClose(fh1)
 

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
CapitalG
Full Member
Members
***
Offline



Posts: 143
Location: Phoenix, Arizona
Joined: Mar 4th, 2003
Re: Combine two text files
Reply #2 - Dec 13th, 2006 at 2:46pm
Print Post Print Post  
Thank you!  Grin
  
Back to top
 
IP Logged