VBdotnet2005
asked on
Append text in vb.net
When I use file.appendtext("myfile"), it does not append right after the first line.
It looks like this
This is a test.
This is a test.
I want the result to be like this
This is a test.
This is a test.
I don't know in advance whether there will be an extra "" line.
It looks like this
This is a test.
This is a test.
I want the result to be like this
This is a test.
This is a test.
I don't know in advance whether there will be an extra "" line.
ASKER
What contains in a text file is this
Resultfile
accountnumber : 12345
/*
I want to remove "/*" from my file, close a file and append new data from db to the same text file.
Right now it look like this
Resultfile
accountnumber : 12345
accountnumber : 67890
/*
instead of
Resultfile
accountnumber : 12345
accountnumber : 67890
/*
Resultfile
accountnumber : 12345
/*
I want to remove "/*" from my file, close a file and append new data from db to the same text file.
Right now it look like this
Resultfile
accountnumber : 12345
accountnumber : 67890
/*
instead of
Resultfile
accountnumber : 12345
accountnumber : 67890
/*
ASKER
This is my code.
dim value as string = file.readalltext(myfile)
value = value.replace("/*", "")
dim sw as new streamwriter(myfile)
sw.writeline(value)
sw.close
dim test as streamwriter = file.appendtext(myfile)
test.writeline("mydata")
test.close
dim value as string = file.readalltext(myfile)
value = value.replace("/*", "")
dim sw as new streamwriter(myfile)
sw.writeline(value)
sw.close
dim test as streamwriter = file.appendtext(myfile)
test.writeline("mydata")
test.close
you also need to remove the new line.
Try this:
value.Remove(value.LastInd exOf(vbNew Line))
Try this:
value.Remove(value.LastInd
I would say that the code is far from perfect. Can you explain why do you
- open your file,
- replace ("/*", "")
- close file
- open file immediately after that
-appebd text
-close file
?
Very expensive exercise in I/O
I'd do:
- open your file,
- replace ("/*", "mydata")
-close file
Code (didn't test)
- open your file,
- replace ("/*", "")
- close file
- open file immediately after that
-appebd text
-close file
?
Very expensive exercise in I/O
I'd do:
- open your file,
- replace ("/*", "mydata")
-close file
Code (didn't test)
dim value as string = file.readalltext(myfile)
' value = value.replace("/*", "") ' this line creates a blank line!!!
value = value.replace("/*", "mydata")
dim sw as new streamwriter(myfile)
sw.write(value)
sw.close
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If so the only way that I can see to get rid of it is to re-write the whole thing.