delphi学习 字符串切割问题(split)
最近做一个项目,要用Delphi,以前从未学过,好是费劲啊,哈哈光是字符串切割这个问题就困扰了几个小时,通过查资料终于解决,在这与大家分享一下
Function split(src: pchar; ch: char):TStringList;
// 分割字符串
var
i: Integer;
tmp : string;
begin
Result:=TStringList.Create;
tmp := '';
showmessage(src);
showmessage(inttostr(Length(src)));
for i := 0 to Length(src) do
begin
if src[i] <> ch then
begin
tmp := tmp + src[i];
end
else
begin
Result.Add(tmp);
tmp := '';
end;
end;
Result.Add(tmp);
end;
说明一下,有些人用Pos函数来对字符串分割,这个函数对中文处理不了,所以最好不要用,
调用方法
先定义一个 var AStrings: TStringList;
在下面使用时 AStrings:=TStringList.Create;然后AStrings:=FaClass.split(pchar(AStr),'|');就把分割后的数组保存在了AStrings中了
相关文档:
谁说Delphi没有哈希?--Delphi中,TStringList和THashedStringList的性能对比
曾经看到很多人在嚷嚷Delphi没有哈希表,这些人的动手意识姑且不论,却还有很多人以此来证明Delphi比别的语言垃圾,实在是...
好,牢骚打住,转接正题。
TStringList是我们常用的字符串列表类型,用法就不在这里赘述,但是,在数据其项数增 ......
function GetFileSizeString(const pFileName: String):String;
var
iFileSize: Int64;
begin
Result := '0';
iFileSize := FileSizeByName(pFileName);
Result := IntToStr(iFileSize);
end;
function WinExecAndWait(strFileName: string; uCmdShow: UINT): DWORD;
var
cAppName: array ......
unit unitFileOP;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
implementation
function GetSys32Dir:String;
var
Sys32Dir: string;
pSys32Dir: array[0..Max_Path] of char;
begin
GetSystemDirectory(pSys32Dir,Max_Pat ......
Rem Delete Delphi temporary file
Rem ****************************
@echo Delete Delphi temporary file
@dir/w/s *.~*
@echo 以上为当前目录及子目录临时文件,请按任意键确认删除!
@pause
@for /r . %%a in (.) do @if exist "%%a\*.~*" del "%%a\*.~*"
@echo 删除成功!
@pause
Rem ************************* ......
unit unitMain;
interface
uses
Registry, shlobj,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TExtForm = class(TForm)
ledExtension: TLabeledEdit;
ledAssocApp: TLabeledEdit;
GetAssocApp: TButton;
AssocTh ......