分割字符串以后如何判断分割的个数?

chengran1984 2009-07-10 12:31:32
function SplitString(Source, Deli: string ): TStringList;stdcall;
var
EndOfCurrentString: byte;
StringList:TStringList;
begin
StringList:=TStringList.Create;
while Pos(Deli, Source)>0 do
begin
EndOfCurrentString := Pos(Deli, Source);
StringList.add(Copy(Source, 1, EndOfCurrentString - 1));
Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);
end;
Result := StringList;
StringList.Add(source);
end;


我用的是这个分割函数,如何显示他分割以后的个数...?
...全文
207 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccrun.com 2009-07-10
  • 打赏
  • 举报
回复
TStringList的DelimitedText并不完美,如果字符串中有空格,会当作分隔符来处理。
ccrun.com 2009-07-10
  • 打赏
  • 举报
回复
TStringList的Count
dinoalex 2009-07-10
  • 打赏
  • 举报
回复
stringlist.count

楼主不用写代码这么麻烦吖,可以直接用下面的

stringlist1.Delimiter:= Deli;
stringlist1.DelimitedText:= Source;
starluck 2009-07-10
  • 打赏
  • 举报
回复
StringList.Count 就是個數

字數就不太明白 你的意思了,那可能要取TEXT再判斷中英文才行。
chengran1984 2009-07-10
  • 打赏
  • 举报
回复
我用的这种方法还是挺好的,就是不会统计字符串分割后的字数.

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧