deliphi 字符串分割_DELPHI 字符串分割处理

DELPHI 字符串分割处理

Code1

Function FindStr(BegSprStr,EdSpStr:String;varSource:String):String;2var3BegStr1Len,EdSpStr2Len,BegStr1Index,EdSpStr2index:integer;4Temp:String;5begin6Temp:=Source;7BegStr1Index:=Pos(BegSprStr,Temp);8BegStr1Len:=Length(BegSprStr);9delete(Temp,BegStr1Index,BegStr1Index+BegStr1Len-1);10EdSpStr2index:=Pos(EdSpStr,Temp);11EdSpStr2Len:=Length(EdSpStr);12Result:=Copy(Temp,1,EdSpStr2index-1);13Delete(Temp,1,EdSpStr2index+EdSpStr2Len-1);14Source:=temp;15end

該函數的功能就是取兩個相隔符之間的字符.

var Source:string

Source:=<1111>string1<1122><2233>string2<3344><4455>string3<5566>;

string1:=FindStr('<1111>','<1122>',Source);

String2:=FindStr('<2233>','<3344>',Source);

String3:=FindStr('<4455>','<5566>',Source);

//---------------------------------------------我想取得一个email地址的用户名

function myuser(email:string):string;

var

i,n:integer;

begin

n:=pos('@',email);

result:=copy(email,0,n-1);//改了一下

end;

//---------------------------------------------

下面就可以取出

leftstr(emaddress,Pos('@',emaddress))

//---------------------------------------------

uses IdGlobal;

User := Fetch(EmailAddress, '@');

//--------------------------------

ExtractStrings(要分隔的字符串,分隔字符串用的字符集合,分隔后排在第一位的消去的字符集合,字符串列表对象)

另一个函数SplitString

//这个我最喜欢用了

function SplitString(const source, ch: string): TStringList;

var

temp, t2: string;

i: integer;

begin

result := TStringList.Create;

temp := source;

i := pos(ch, source);

while i <> 0 do

begin

t2 := copy(temp, 0, i - 1);

if (t2 <> '') then

result.Add(t2);

delete(temp, 1, i - 1 + Length(ch));

i := pos(ch, temp);

end;

result.Add(temp);

end;

例子:

st := SplitString('xxx@hoho.com', '@');

st[0] = 'xxx';

st[1] = 'hoho.com';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值