Click here to Skip to main content
15,846,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a Text File (.txt).Whose Structure is as Below

1. qwerty^^saasd^^^adadasd^^
2. asdasdas^^adasdasd^^^asasdasd^^
3. weqweqwew^^^dasdadasd^^^asdasd^^^

it goes on accordingly
I want to pass a text through a Textbox
and want it to append at the last Postion of
First line.

Let the text to be passed is 1234567

so that my new TextFile should be like as below

1. qwerty^^saasd^^^adadasd^^1234567
2. asdasdas^^adasdasd^^^asasdasd^^
3. weqweqwew^^^dasdadasd^^^asdasd^^^

Updated 27-Apr-12 2:07am

What have you tried so far? One solution is to read your text file into a string array, add your text to the first array element and then write the string array back out.

Something like
Dim lines(65535) As String
szLines = File.ReadAllLines(sourceFile)

will read the file 'sourceFile' into the array 'lines'

Once the 'lines' array has been populated you can't change it, so you will need to copy the string array into another one which you can change (which is where you will add your text), and then write that array to a file.

Hope that helps!
Share this answer
As given in Solution 1 by derek9999, the Text can be read into an array and there is no need to fix the array size.
Dim lines as string() = System.IO.File.ReadAllLines will do
After appending the text to the first line the lines can be written back to the file using the
System.IO.File.WriteAllLines Method[^]
Share this answer
derek9999 27-Apr-12 6:46am    
Yes, you don't need to size the array. Cut and paste casualty from some old code!
Karwa_Vivek 27-Apr-12 6:49am    
But how can I find the end of First line so that i can append the text at that position..Reading back is ok but how i will append it in the end of first line
VJ Reddy 27-Apr-12 7:00am    
lines(0) &= "Text to be appended"
will append the text at the end.
derek9999 27-Apr-12 7:02am    
You don't need to find the end, just use something like newArray(0) = oldArray(0) + "1234567"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900