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是我们常用的字符串列表类型,用法就不在这里赘述,但是,在数据其项数增 ......
最近要做一个图书管理系统,并且是用Delphi软件开发,很多都不懂,本来是可以从网上下载,学习一下的,可是不知道怎么破解登陆密码,运行时没办法登陆进去,5555~~好好学习,有高手指点就好了…… ......
unit DvsLinkingClass;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms, Dialogs;
type
PRecLinkNode = ^RecLinkNode;
RecLinkNode = record
NodeMsg: String;
Counter: Integer;
Previous: PRecLinkNode;
Next: PRecLinkNode;
end;
TLinkingClass = class
......
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 ......
unit unitMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2 ......