By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

replacing lines

P: 3
Hello!
I`m trying to replace only one line in txt file!

Example!
test.txt file
AAA = 1
AAA = 2
AAA = 3
BBB = 2

final (after replacing) test.txt file
KKK = 1
AAA = 2
AAA = 3
BBB = 2

So I have to replace concrete line in file! Usual replace change all lines whitch contains AAA enty.
Thanks!
Jul 7 '08 #1
Share this Question
Share on Google+
3 Replies


debasisdas
Expert 5K+
P: 8,127
kindly post the code that you are working on.
Jul 7 '08 #2

P: 3
There is the code:

Sub lol()
Dim lOpenFile As Long
Dim sFileText As String
Dim sFileName As String

sFileName = "C:\test.txt"
'open the file and read it into a variable
lOpenFile = FreeFile
Open sFileName For Input As lOpenFile
sFileText = Input(LOF(lOpenFile), lOpenFile)
Close lOpenFile
startPos = 1
maxToReplace = 1
sFileText = Replace(sFileText, "AAA", "TEST")
'write it back to the file
startPos = 1
maxToReplace = 1
lOpenFile = FreeFile
Open sFileName For Output As lOpenFile
Print #lOpenFile, sFileText
Close lOpenFile
End Sub
Jul 8 '08 #3

P: 3
Ok, thanks! I found the solution ;)
Jul 8 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.