拆分字符串需要自己写代码 这不如C#方便 比如 ----------- var s,s1,xxx:string; begin S := ',+0054,+1753,+0052,+1678,+0189'; while pos(',',s)> 0 do begin xxx := copy(s,pos(',',s)+1,length(s)-pos(',',s)); delete(s,pos(',',s)+1,length(s)-pos(',',s)); s1 := s ;//这里没有去掉',' memo1.Lines.Add(s1); s := xxx; end; end;
没有现成的,主要的VB中已经有这样的现成数据结构类型(HashTable等), delphi中对应hashTable的类:TList,TStringList(TStringList 中有 Value 可以和key对应)TStringList是TString的集合,你可以直接自己建类或结构啊 THash { int; TString; }
没有现成的,主要的VB中已经有这样的现成数据结构类型(HashTable等), delphi中对应hashTable的类:TList,TStringList(TStringList 中有 Value 可以和key对应)TStringList是TString的集合,你可以直接自己建类或结构啊 THash { int; TString; } -------------------- 拆分字符串需要自己写代码 这不如C#方便 比如 ----------- var s,s1,xxx:string; begin S := ',+0054,+1753,+0052,+1678,+0189'; while pos(',',s)> 0 do begin xxx := copy(s,pos(',',s)+1,length(s)-pos(',',s)); delete(s,pos(',',s)+1,length(s)-pos(',',s)); s1 := s ;//这里没有去掉',' memo1.Lines.Add(s1); s := xxx; end; end; ---------------------------------- 自己写函数,应该不难啊 ^_^
给你一个我自己写的函数 //函数名:SplitString //参数:Source:待分割的字符串;ch:分割符 //返回值:以ch分割source得到的字符串列表 //函数举例:若source为A%B%C%D,ch为%,则返回('A','B','C','D') 。 function SplitString(Source, ch: string): TStringList; var temp: string; i: integer; begin Result := TStringList.Create; //如果是空自符串则返回空列表 if Source = '' then exit; temp := Source; i := pos(ch, Source); while i <> 0 do begin Result.add(copy(temp, 0, i - 1)); Delete(temp, 1, i); i := pos(ch, temp); end; Result.add(temp); end;
var S: string; SL: TStringList; begin S := '123,456,789'; SL := TStringList.Create; ExtractStrings([','], [], PChar(S), SL); ShowMessage(SL.Text); SL.Free; end; var sl:TStringList; i:integer; begin sl:=TstringList.Create; sl.Delimiter:=','; sl.DelimitedText:='asdf,asdfas,asdf,fff,dfff'; for i:=0 to sl.Count-1 do begin showMessage(sl.Strings[i]); end;
var StringList:TStringList; begin ExtractStrings([';'],[' '],PChar('A;B;C'),StringList); end;
2、没有用过VB和C#,所以不知道怎么类比
这不如C#方便
比如
-----------
var
s,s1,xxx:string;
begin
S := ',+0054,+1753,+0052,+1678,+0189';
while pos(',',s)> 0 do
begin
xxx := copy(s,pos(',',s)+1,length(s)-pos(',',s));
delete(s,pos(',',s)+1,length(s)-pos(',',s));
s1 := s ;//这里没有去掉','
memo1.Lines.Add(s1);
s := xxx;
end;
end;
没有现成的,主要的VB中已经有这样的现成数据结构类型(HashTable等),
delphi中对应hashTable的类:TList,TStringList(TStringList 中有 Value 可以和key对应)TStringList是TString的集合,你可以直接自己建类或结构啊
THash
{
int;
TString;
}
delphi中对应hashTable的类:TList,TStringList(TStringList 中有 Value 可以和key对应)TStringList是TString的集合,你可以直接自己建类或结构啊
THash
{
int;
TString;
}
--------------------
拆分字符串需要自己写代码
这不如C#方便
比如
-----------
var
s,s1,xxx:string;
begin
S := ',+0054,+1753,+0052,+1678,+0189';
while pos(',',s)> 0 do
begin
xxx := copy(s,pos(',',s)+1,length(s)-pos(',',s));
delete(s,pos(',',s)+1,length(s)-pos(',',s));
s1 := s ;//这里没有去掉','
memo1.Lines.Add(s1);
s := xxx;
end;
end;
----------------------------------
自己写函数,应该不难啊
^_^
//函数名:SplitString
//参数:Source:待分割的字符串;ch:分割符
//返回值:以ch分割source得到的字符串列表
//函数举例:若source为A%B%C%D,ch为%,则返回('A','B','C','D') 。
function SplitString(Source, ch: string): TStringList;
var
temp: string;
i: integer;
begin
Result := TStringList.Create;
//如果是空自符串则返回空列表
if Source = '' then exit;
temp := Source;
i := pos(ch, Source);
while i <> 0 do
begin
Result.add(copy(temp, 0, i - 1));
Delete(temp, 1, i);
i := pos(ch, temp);
end;
Result.add(temp);
end;
S: string;
SL: TStringList;
begin
S := '123,456,789';
SL := TStringList.Create;
ExtractStrings([','], [], PChar(S), SL);
ShowMessage(SL.Text);
SL.Free;
end;
var
sl:TStringList;
i:integer;
begin
sl:=TstringList.Create;
sl.Delimiter:=',';
sl.DelimitedText:='asdf,asdfas,asdf,fff,dfff';
for i:=0 to sl.Count-1 do
begin
showMessage(sl.Strings[i]);
end;
StringList:TStringList;
begin
ExtractStrings([';'],[' '],PChar('A;B;C'),StringList);
end;