如何编写一个函数,将字符串按字节长度进行分割处理?

2026-04-10 21:441阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计318个文字,预计阅读时间需要2分钟。

如何编写一个函数,将字符串按字节长度进行分割处理?

delphifunction SplitString(source: string; sleng: Integer): TStrings;var i: Integer;begin Result :=TStringList.Create; try i :=1; while i <=Length(source) do begin if (i + sleng - 1) <=Length(source) then Result.Add(Copy(source, i, sleng)) else Result.Add(Copy(source, i, Length(source) - i + 1)); Inc(i, sleng); end; finally Result.Free; end;end;

此字符串分割函数用delphi编写,可以适应字符串中存在双字节字符和单字节字符。

阅读全文

本文共计318个文字,预计阅读时间需要2分钟。

如何编写一个函数,将字符串按字节长度进行分割处理?

delphifunction SplitString(source: string; sleng: Integer): TStrings;var i: Integer;begin Result :=TStringList.Create; try i :=1; while i <=Length(source) do begin if (i + sleng - 1) <=Length(source) then Result.Add(Copy(source, i, sleng)) else Result.Add(Copy(source, i, Length(source) - i + 1)); Inc(i, sleng); end; finally Result.Free; end;end;

此字符串分割函数用delphi编写,可以适应字符串中存在双字节字符和单字节字符。

阅读全文