文本我有一个具有以下数据的文本文件:解析德尔福
dgm P1
s0:->b1
*s1:b2->b1
S2:b2->b1,b3
dgm P2
s0:->b2
*s1:b1,b3->b2
我要分析此文件,以获得一个数组,其元素将包含每个 DGM年代,直到下一个。也就是说,第一个元素是:
dgm P1
s0:->b1
*s1:b2->b1
S2:b2->b1,b3
第二个元素是:
dgm P2
s0:->b2
*s1:b1,b3->b2
等 请我如何去在德尔福。我正在寻找更好的方法来做到这一点。我试着从文件加载到TStringList。
begin
str:=TstringList.Create;
try
str.LoadFromFile('example.txt');
for i:=0 to str.Count -1 do
if str[i] ='dgm' then
//get the position, add it to an array;
//get the next position, till the end;
//use the positions to divide up the string
finally
str.Free;
但是,这是行不通的,我也觉得可能是一个更好的办法 来处理这个比我简要介绍。
什么不工作呢?你需要花时间来阅读[help]和[mcve]。 –
':='是赋值,使用'='进行比较。您可能会更好地读出前3个字符与'dgm'比较的rs。如何区分大小写?空白?这种语言的规则是什么?你知道吗?你知道如何执行字符串的基本操作吗?看起来你没有。如果你不知道,那么你会奋斗。 –
它不工作,因为你检查'dmg'字符串,但文件有'dmg P1','dmg P2'等 而你需要替换:= with =,正如David指出 –