At first glance, I asked a comparison question: how to extract the specified content from a file?

Source: Internet
Author: User
At first glance, I asked a comparison question: how to extract the specified content from a file? Development and Application of VCL Components
Http://www.delphi2007.net/DelphiVCL/html/delphi_20061223005343172.html
The data content is as follows:
72800.000 38.91898908-77.06621526 40.7516 1112188.776-4842946.894 3985349.437 6.3756030408e-007 0.82 4.48 8 8 0.00000 0 0 0.000
172830.000 38.91898135-77.06620653 41.6280 1112189.787-4842947.914 3985349.320 6.4061321369e-007 1.05 4.51 8 8 0.00833 0 0 30.000
172860.000 38.91895879-77.06620348 47.2173 1112191.370-4842953.626 3985350.883 6.5588341696e-007 1.45 4.09 9 0.01667 0 1 0.000
172890.000 38.91895839-77.06620595 47.4124 1112191.202-4842953.850 3985350.971 6.5682624245e-007 1.46 4.11 9 0.02500 0 1 30.000
172920.000 38.91896101-77.06620285 47.2516 1112191.395-4842953.489 3985351.097 6.5675199614e-007 1.42 4.12 9 0.03333 0 2 0.000
172950.000 38.91896486-77.06620350 46.7696 1112191.196-4842952.875 3985351.126 6.5579189199e-007 1.32 4.14 9 0.04167 0 2 30.000
172980.000 38.91896559-77.06620199 46.4309 1112191.253-4842952.539 3985350.977 6.5487505133e-007 1.28 4.15 9 0.05000 0 3 0.000
173010.000 38.91896711-77.06620177 45.8964 1112191.155-4842952.026 3985350.772 6.5348139425e-007 1.25 4.17 9 0.05833 0 3 30.000
173040.000 38.91896774-77.06619940 45.3632 1112191.252-4842951.533 3985350.492 6.5210196616e-007 1.19 4.18 9 0.06667 0 4 0.000
173070.000 38.91896760-77.06619931 45.6531 1112191.313-4842951.761 3985350.662 6.5307188787e-007 1.23 4.19 9 0.07500 0 4 30.000
173100.000 38.91896831-77.06619921 45.5575 1112191.294-4842951.638 3985350.663 6.5291762658e-007 1.17 4.21 9 9 0.08333 0 5 0.000
What method can be used to extract the first value in each row, which is expressed in scientific notation? It is best to provide the source code. Thank you!


Use tstringlist

Each row of data can be conveniently retrieved.

VaR
List1: tstringlist
Begin
List1; = tstringlist. Create;
List1.loadfrom (filename );
...


Then take the first value.

Tstringlist

But how to set the value? Can you tell me in detail? Thank you.

You can extract data in a single row and use ''as the end mark.

Strtofloat can recognize scientific notation.

I was not quite familiar with Delphi, but I didn't know that tstringlist is a method to extract data from a row,
Weixiaohua (I love Delphi). How do you use ''as the end mark?CodeIt's best to study it.

Function getvalidstr3 (STR: string; var DEST: string; const divider: array of char): string;
Const
Buf_size = 20480; // $ 7fff;
VaR
Buf: array [0 .. buf_size] of char;
Bufcount, Count, srclen, I, arrcount: longint;
Ch: Char;
Label
Catch_div;
Begin
Ch: = #0; // Jacky
Try
Srclen: = length (STR );
Bufcount: = 0;
Count: = 1;

If srclen> = BUF_SIZE-1 then begin
Result: = '';
DeST: = '';
Exit;
End;

If STR = ''then begin
DeST: = '';
Result: = STR;
Exit;
End;
Arrcount: = sizeof (divider) Div sizeof (char );

While true do begin
If count <= srclen then begin
Ch: = STR [count];
For I: = 0 to arrcount-1 do
If CH = divider [I] Then
Goto catch_div;
End;
If (count> srclen) then begin
Catch_div:
If (bufcount> 0) then begin
If bufcount <BUF_SIZE-1 then begin
Buf [bufcount]: = #0;
DeST: = string (BUF );
Result: = copy (STR, Count + 1, srclen-count );
End;
Break;
End else begin
If (count> srclen) then begin
DeST: = '';
Result: = copy (STR, Count + 2, SrcLen-1 );
Break;
End;
End;
End else begin
If bufcount <BUF_SIZE-1 then begin
Buf [bufcount]: = CH;
INC (bufcount );
End; // else
// Showmessage ('buf _ SIZE overflow! ');
End;
INC (count );
End;
Except
DeST: = '';
Result: = '';
End;
End;

The above function is what you need. The usage is as follows:
Tstr: = getvalidstr3 (tstr, S18, ['', #9]);
Tstr: = getvalidstr3 (tstr, s1c, ['', #9]);
Tstr: = getvalidstr3 (tstr, S20, ['', #9]);
The extracted data can be converted into numbers.

Weixiaohua (I love Delphi) thanks for your reply, but this function is a little difficult for me in the early stage. I don't understand it. I wonder if there is any relatively simple method, if I don't have it, I will post it separately ,.
I have seen so many enthusiastic people here for the first time. Thank you very much and csdn ..

You don't have to worry about the specific implementation of that function.
Assume that your data is in datalist.
Datalist: = tstringlist. Create;
Datalist. loadfromfile ('x: \ xx.txt ');
For I: = datalist. Count-1 do
Begin
Sline: = datalist. Strings [I];
Sline: = getvalidstr3 (Sline, str1, ['', #9]); // assume that the first line is str1: = 72800.000;
// Sline: = getvalidstr3 (Sline, str1, ['', #9]); // You can execute str1: = 38.91898908 once.
Strtofloat (str1); // The number you need after conversion.
End;

Up

Weixiaohua (I love Delphi) Thanks. Please check if the score has been sent ..

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.