delphi 中 字符串分割函数 ExtractStringsEx,是ExtractStrings函数的扩展
来源:互联网 发布:大学生淘宝开店卖什么 编辑:程序博客网 时间:2024/05/21 22:22
使用ExtractStrings函数发现不能分割出空串,很是郁闷,发现delphi提供ExtractStrings的代码,打开看看修改了一下,实现增加空串的功能,如下
function ExtractStringsEx(Separators, WhiteSpace: TSysCharSet; Content: PChar;
Strings: TStrings): Integer;
var
Head, Tail: PChar;
EOS, InQuote: Boolean;
QuoteChar: Char;
Item: string;
begin
Result := 0;
if (Content = nil) or (Content^=#0) or (Strings = nil) then Exit;
Tail := Content;
InQuote := False;
QuoteChar := #0;
Strings.BeginUpdate;
try
repeat
while Tail^ in WhiteSpace + [#13, #10] do Tail := StrNextChar(Tail); //忽略每个分割前面的字符
Head := Tail;
while True do
begin
while (InQuote and not (Tail^ in [QuoteChar, #0])) or
not (Tail^ in Separators + [#0, #13, #10, '''', '"']) do Tail := StrNextChar(Tail);
if Tail^ in ['''', '"'] then
begin
if (QuoteChar <> #0) and (QuoteChar = Tail^) then
QuoteChar := #0
else if QuoteChar = #0 then
QuoteChar := Tail^;
InQuote := QuoteChar <> #0;
Tail := StrNextChar(Tail);
end else Break;
end;
EOS := Tail^ = #0;
if (Head <> Tail) and (Head^ <> #0) then
begin
if Strings <> nil then
begin
SetString(Item, Head, Tail - Head);
Strings.Add(Item);
end;
Inc(Result);
end
else if Head^ <> #0 then //如果头尾相同则增加空串 else if 后面的内容是我增加的
begin
if Strings <> nil then
Strings.Add('');
Inc(Result);
end;
Tail := StrNextChar(Tail);
until EOS;
finally
Strings.EndUpdate;
end;
end;
Strings: TStrings): Integer;
var
Head, Tail: PChar;
EOS, InQuote: Boolean;
QuoteChar: Char;
Item: string;
begin
Result := 0;
if (Content = nil) or (Content^=#0) or (Strings = nil) then Exit;
Tail := Content;
InQuote := False;
QuoteChar := #0;
Strings.BeginUpdate;
try
repeat
while Tail^ in WhiteSpace + [#13, #10] do Tail := StrNextChar(Tail); //忽略每个分割前面的字符
Head := Tail;
while True do
begin
while (InQuote and not (Tail^ in [QuoteChar, #0])) or
not (Tail^ in Separators + [#0, #13, #10, '''', '"']) do Tail := StrNextChar(Tail);
if Tail^ in ['''', '"'] then
begin
if (QuoteChar <> #0) and (QuoteChar = Tail^) then
QuoteChar := #0
else if QuoteChar = #0 then
QuoteChar := Tail^;
InQuote := QuoteChar <> #0;
Tail := StrNextChar(Tail);
end else Break;
end;
EOS := Tail^ = #0;
if (Head <> Tail) and (Head^ <> #0) then
begin
if Strings <> nil then
begin
SetString(Item, Head, Tail - Head);
Strings.Add(Item);
end;
Inc(Result);
end
else if Head^ <> #0 then //如果头尾相同则增加空串 else if 后面的内容是我增加的
begin
if Strings <> nil then
Strings.Add('');
Inc(Result);
end;
Tail := StrNextChar(Tail);
until EOS;
finally
Strings.EndUpdate;
end;
end;
- delphi 中 字符串分割函数 ExtractStringsEx,是ExtractStrings函数的扩展
- [update]Delphi分割字符串的函数 ExtractStrings
- Delphi分割字符串的函数--ExtractStrings
- Delphi分割字符串的函数ExtractStrings
- 分割字符串函数ExtractStrings
- ExtractStrings函数分割字符串详解
- DELPHI中优秀的字符串分割函数
- Delphi中优秀的字符串分割函数
- Delphi中优秀的字符串分割函数
- Delphi分割字符串的函数
- Delphi分割字符串的函数
- DELPHI字符串分割函数
- Delphi字符串分割函数
- 分割字符串 ExtractStrings
- ExtractStrings函数使用例子
- Delphi中的一些字符串分割的函数收集
- Delphi 自带的字符串分割函数split
- Delphi自带的字符串分割函数Split
- 如果你还活着!
- IE6下,不允许向innerHTML中赋值形如“”的代码
- 在DirectX9.0中使用Mesh (1)
- java.net.MalformedURLException: no protocol: 5.0/webapps/ra/WEB-INF/classes/]异常处理
- SU01修改用户的role的有效期限
- delphi 中 字符串分割函数 ExtractStringsEx,是ExtractStrings函数的扩展
- 在DirectX9.0中使用Mesh (2)
- Cannot create PoolableConnectionFactory ([Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.)错误
- 一些.net开源项目
- JavaDoc使用注释
- ECC6 SR2 ACCESS KEY破解细节
- 可变顶点格式
- UTF8 与 UCS
- 图片防盗链