如何使用Delphi实现按字节长度分割字符串的功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计330个文字,预计阅读时间需要2分钟。
delphifunction SplitString(source: string; sleng: Integer): TStrings; stdcall;var i: Integer; tempStr: string;begin Result :=TStrings.Create; try i :=1; while i <=Length(source) do begin if (i + sleng - 1) <=Length(source) then begin tempStr :=Copy(source, i, sleng); Result.Add(tempStr); i :=i + sleng; end else begin tempStr :=Copy(source, i, Length(source) - i + 1); Result.Add(tempStr); Break; end; end; finally FreeAndNil(Result); end;end;
此字符串分割函数用delphi编写,可以适应字符串中存在双字节字符和单字节字符。
本文共计330个文字,预计阅读时间需要2分钟。
delphifunction SplitString(source: string; sleng: Integer): TStrings; stdcall;var i: Integer; tempStr: string;begin Result :=TStrings.Create; try i :=1; while i <=Length(source) do begin if (i + sleng - 1) <=Length(source) then begin tempStr :=Copy(source, i, sleng); Result.Add(tempStr); i :=i + sleng; end else begin tempStr :=Copy(source, i, Length(source) - i + 1); Result.Add(tempStr); Break; end; end; finally FreeAndNil(Result); end;end;
此字符串分割函数用delphi编写,可以适应字符串中存在双字节字符和单字节字符。

