可能重複:
Delphi: Extract string from a text file using 2 delimiters如何在delphi中的兩個開始和結束字符串之間找到一個字符串?
如何找到兩者之間的字符串開始和結束串在Delphi
可能重複:
Delphi: Extract string from a text file using 2 delimiters如何在delphi中的兩個開始和結束字符串之間找到一個字符串?
如何找到兩者之間的字符串開始和結束串在Delphi
如果你是快樂與天真的解決方案,看看這個SO:Extract string from a text file using 2 delimiters
如果您想要進行代碼分析,您實際上需要一個完整的語言解析器capa理解評論,條件編譯+所有其他預編譯器選項。
uses
StrUtils;
...
const
sBegin = 'begin';
sEnd = 'end';
var
i1, i2: Integer;
sSubstr: String;
...
i1 := Pos(sBegin, s);
if i > 0 then begin
i2 := PosEx(sEnd, s, i1 + Length(sBegin));
if i2 > 0 then begin
sSubstr := Copy(s, i1 + Length(sBegin), i2 - (i1 + Length(sBegin)));
// process the delimited substring
end;
end;
注:
去Extract string from a text file using 2 delimiters
複製功能,並調用它像這樣:
`ExtractText('Hi my name is$John and I''m happy/today','$','/')`;
它會返回 '約翰和I''m快樂。'
例子:
ShowMessage(ExtractText('Hello,World!', ',' ,'!'));
它會在一個彈出顯示的 '世界'。
function ExtractText(const Str:string; const Delim1,Delim2:char):string; 我該如何使用這個功能?需要示例 – 2011-02-10 22:08:55