Text File : how to READ, WRITE or REWRITE a text file

Franco_Festi
Member Posts: 19
Hi guys,
i've looked up and down this forum many times, but i still haven't found what i was looking for.
I've got a text file, like this.
aaaaaaaaa
bbbbbbbbb
ccccccccc
ddddddddd
eeeeeeeee
I need to rewrite the 3rd line. Something like this :
aaaaaaaaa
bbbbbbbbb
ppp
ddddddddd
eeeeeeeee
Well. I know how to place the pointer in the right position (TEXTMODE = FALSE, file.SEEK(Position) ) but i've got problems when it comes to write my string.
My code is (example) :
linelength : integer;
index : integer;
string : text[100];
string := 'ppp';
FOR index := 1 TO LineLength
File.WRITE(string[index]);
The point is : i wanted to avoid inserting CRLF at the end of my line. It worked, but the result wasn't so good.
aaaaaaaaa
bbbbbbbbb
p p p ccccccccc (as you can see, the old line is still there)
ddddddddd
eeeeeeeee
Furthermore, openin my text file with WordPad i see that after every single char appears a strange "square symbol" (i think you know what i mean)... using NotePad it's just a space.
So... i need your help guys !
Thank you !!
Franco
i've looked up and down this forum many times, but i still haven't found what i was looking for.
I've got a text file, like this.
aaaaaaaaa
bbbbbbbbb
ccccccccc
ddddddddd
eeeeeeeee
I need to rewrite the 3rd line. Something like this :
aaaaaaaaa
bbbbbbbbb
ppp
ddddddddd
eeeeeeeee
Well. I know how to place the pointer in the right position (TEXTMODE = FALSE, file.SEEK(Position) ) but i've got problems when it comes to write my string.
My code is (example) :
linelength : integer;
index : integer;
string : text[100];
string := 'ppp';
FOR index := 1 TO LineLength
File.WRITE(string[index]);
The point is : i wanted to avoid inserting CRLF at the end of my line. It worked, but the result wasn't so good.
aaaaaaaaa
bbbbbbbbb
p p p ccccccccc (as you can see, the old line is still there)
ddddddddd
eeeeeeeee
Furthermore, openin my text file with WordPad i see that after every single char appears a strange "square symbol" (i think you know what i mean)... using NotePad it's just a space.
So... i need your help guys !
Thank you !!
Franco
0
Comments
-
I think there is no way how to do that. You can only copy the file under another name, read it until the point you want to change, write the new line, and continue with copying the rest of the file (skipping the replaced line).0
-
kine wrote:I think there is no way how to do that. You can only copy the file under another name, read it until the point you want to change, write the new line, and continue with copying the rest of the file (skipping the replaced line).
Thanks for replying. The fact is i've already thought about it, and i can't do it. The text file i'm using is a shared file. A second software is using it so i can't delete/replace it.
(by the way, i asked them..the answer wasn't what i wanted. Maybe it's just lazyness..but my hands are tied...)
Thank you anyway.
Franco0 -
Sared file and you are changing it when another app is accessing it? I can only be sorry for you.. ](*,)
In these days using file as place for exchanging the information is not way how to do that.0 -
kine wrote:Sared file and you are changing it when another app is accessing it? I can only be sorry for you.. ](*,)
In these days using file as place for exchanging the information is not way how to do that.
I know! That's exactly what i told them! I feel like i'm still living in the middle age of IT! Bleah!
:?0 -
Use the streams example from reynolds. Looks really easy:
viewtopic.php?f=23&t=29313&p=146950#p1469500 -
ajhvdb wrote:Use the streams example from reynolds. Looks really easy:
viewtopic.php?f=23&t=29313&p=146950#p146950
That example doesn't do what i need - it replaces a string you're already supposed to know -anyway, it gives me an idea.
1. I can read the line in the position i need to replace.
2. Save the value of this line inside a global (bigtext).
3. Search for this line inside the file (maybe using the example in the link).
4. Replace the target line with a new one.
I'll try, then i'll let you know.
Thank you0 -
Franco_Festi wrote:ajhvdb wrote:Use the streams example from reynolds. Looks really easy:
viewtopic.php?f=23&t=29313&p=146950#p146950
That example doesn't do what i need - it replaces a string you're already supposed to know -anyway, it gives me an idea.
1. I can read the line in the position i need to replace.
2. Save the value of this line inside a global (bigtext).
3. Search for this line inside the file (maybe using the example in the link).
4. Replace the target line with a new one.
I'll try, then i'll let you know.
Thank you
still having the same old problem. Using two different text files the result is ok, but not good for my purpose : i must use the same file without copy, delete or rename.
](*,)0 -
go to your position, write the del char until you meet a crlf and then write your string?
(just went to see the ascii table, perhaps go to the end of the line and write the backspace char (8))0 -
The tools you have in NAV are not able to "remove" part inside the file. You can do only something like:
Using two File variables. One for reading (FileR), one for reading/writing (FileRW). Open same file with both. Set the FileR after the text you want to change. Set the FileRW to the position of the change, write the new part. After that read everything from FileR and write it into FileRW. After all is read from FileR, use FileRW.TRUNC to truncate rest of the file.
You need to think about the problem in his way: you can only "overwrite" the data in the file, you cannot remove part of them. The additional part you want to "remove" must be overwritten with the rest of the file, you can only truncate the end of the file.
But I do not know, if it will works when the replaced part is shorten than the inserted one (whn the FileR will read on modified par by FileRW).
I hope that you catch what I tried to describe... 8)0 -
Hi,
Just wanted to say that this is an excellent post. I never used BigText before. But after seeing this code example, I will use it more now.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions