From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
10-18-2011 03:04 AM - edited 10-18-2011 03:06 AM
Hi,
I want read a particular line in a text file till the end of the line(only end of the particulat line not end of the file). say for example I am reading 3rd line starting from a particulat start point. So what i did is
I used read from text file fn and I gave '-1' to read entire file then
I use string subset and gave offset value to tell where I want to start and for the length I dont want to specify how many characters to read instaed I want to give fetch till end of the line.
Can any one tell if u know
Thanks in advance
--saamy
10-18-2011 03:22 AM
In the other thread, I have already suggested using CopyString (, , "", , ) ...
As I understand you have read one line from a text file into a buffer and now want to extract only part of it, starting at a given offset, and the end given by the end of the line. In my opinion, you could use the above mentioned function...
The last parameter of CopyString, Maximum # Bytes, specifies the maximum number of bytes, excluding the ASCII NUL, to copy into the target. If you do not want to specify a maximum number of bytes to copy, use –1.
10-18-2011 03:26 AM
There are a couple of ways to do this.
The easiest is to open the file and read it line-by-line with OpenFile + ReadLine in a loop; once the desired line has been reached, extract the relevant portion of it.
This method performs a disk access for each line read: for this reason it can be slow in case of large files with several lines.
Another way is to read the entire file in memory and scan it, as you are doing now. This method is a little bit more complicated but is could be very fast; in case of huge files you may have problems in reading the entire file in memory. If you want to go this way, I suggest you take a look at the code posted by Nick B in this thread, which can simplify the task of splitting file content in lines.
10-18-2011 03:34 AM
Thanks Wolfgang, Yes In that thread itself I replied you. What I did so far is using "read from text file" function I am reading the entire file by using "-1" ang by using string subset I have given my starting position of the string to read (say for example my offset no is 108 so now my starting position is 3rd row and starting some where at the middle) Now my doubt is how to read till end of that particular line(as per our example - till 3rd row).
10-18-2011 03:41 AM
Thanks a lot Roberto. Yes, 2nd method is apt for my application. I go through the link and ask u if I face any problem. Once again thanks 🙂
10-18-2011 04:34 AM
Hi Wolfgang, saw that thread which you shared previously. I could not undertand clearly. I clearly explained what i did so far. If you dont mind can u plz tell me how to proceed further steps to solve this matter
10-19-2011 01:40 AM
Hi saamy,
I was assuming that you open the file and read it line-by-line in a loop, i.e. Roberto's method 1 (that's what I usuallly do but my files aren't that long). As this is not the case, you may politely ignore my contribution and follow the link provided by Roberto instead
10-19-2011 08:19 PM
Hi Roberto & Wolfgang,
Thanks a lot for your support. I solved that problem, I can read line by line and fetch particular portion of data.
--
saamy
05-21-2013 04:39 PM
RobertoBozzolo wrote:
The easiest is to open the file and read it line-by-line with OpenFile + ReadLine in a loop; once the desired line has been reached, extract the relevant portion of it.
I seem to missing a detail here. Where in OpenFile or ReadLine is there an option to specify the line? I don't see that as an option.
05-21-2013 05:27 PM
ElectroLund ha scritto:I seem to missing a detail here. Where in OpenFile or ReadLine is there an option to specify the line? I don't see that as an option.
That's because there isn't!
The underlining idea was to use ReadLine in a loop until desired line has been reached. If you know the line number to reach you can simply use a loop that reads and discards n-1 lines, next you read and manage the line you want. If you don't know the line number, in the loop you read a line and parse its content looking for the informations you are searching.
Provided the file can fit in memory, you may speed up the process by reading the whole file at once and parsing its content in memory in a similar way: look at nickb posts in this thread which offer a very good solution to this problem.