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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write a character to a file

Status
Not open for further replies.

bitwise

Programmer
Mar 15, 2001
269
US
I'm new to VB file access. What is the most efficient way to write a ',' to the front of each line in a file. For example say the file looks like this:

First,Second,Third
First,Second,Third,Fourth
First,Second
First,Second,Third

How can I make the file look like this:

,First,Second,Third
,First,Second,Third,Fourth
,First,Second
,First,Second,Third

Thanks,
bitwise
 
dim path as string 'holds the path to the original file
dim f as integer 'used to hold the file number
dim temp as string ' used to hold the contents of the file
dim temp1() as string
dim upper as long,i as long

path = "c:\temp.txt"

f = freefile

open path for input as #f

temp = String$(LOF(f), 32)
Get #f, 1, temp 'grab the entire file all at once and put it into memory

close #f

temp1 = split(temp,vbnewline)
upper = ubound(temp1)
f = freefile

open path for output as #f

for i = 0 to upper
print #f, "," & temp1(i)
next i
close #f

This should do what you need really quickly
Troy Williams B.Eng.
fenris@hotmail.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top