Home > Back-end >  Delphi string loop intercept import SQL table
Delphi string loop intercept import SQL table

Time:09-24

String example:
String: 1 D E21001 15.09 30002 17.9 01005706 0626 600002584547 31003 20004 31005 30006 43.89 58.0 115.2 15.0 8.1 21007
String: 2 D 01000101 E006 556 E30006 49.16 21007 22.5 21008 3.4 11022 23.4 30026 0.87 10057 20.4
-- -- -- -- -- -- -- --
The string length is differ, but starting from the fourth (E) in the beginning, is regular,

The string 1 export data requirements:
Table fields, a total of 5, the first field import of 01005706 the second import 0626 third, 600002584547 fourth E21001 15.09 v
The second line of the first field import of 01005706 the second import 0626 third, 600002584547 fourth 30002 fifth 17.9
The third line the first field import of 01005706 the second import 0626 third, 600002584547 fourth 31003 fifth 15.0
,,,,,,,,,,
The last line of the first field import of 01005706 the second import 0626 third, 600002584547 fourth 21007 fifth 8.1
By analogy, the first three fields are the same string, take the value behind the fourth five fields (starting with E,)

The second file
The first line of the first field import of 01000101 the second import E006 third, 556 fourth E30006 fifth 49.16
The second line of the first field import for the second import E006 01000101 third, 556 fourth 21007 fifth 22.5
The third line the first field import of 01000101 the second import E006 third, 556 fourth 21008 fifth 3.4

-- -- -- -- -- -- -- -- -- -- --
The last line of the first field import of 01000101 the second import E006 10057 third, 556 fourth 20.4 5

CodePudding user response:

Can use TStringList automatically split the string, starting from the third to use

CodePudding user response:

One, the key is to write a decomposition process of string:

Procedure SliptStr (s: a string; VarS1, S2, S3, S4, S5: string).

There are two way two, read the database
1, SQL statements directly, finalized database;
In the table 2, through the TDBGrid, read,

Three, the operating structure
For line TXT cycle
Decomposition characters
Generate SQL statements
Execute SQL
end;
  • Related