zoukankan      html  css  js  c++  java
  • DELPHI 字符串分割处理

    DELPHI 字符串分割处理

    Code

    該函數的功能就是取兩個相隔符之間的字符.
    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';

  • 相关阅读:
    7月的尾巴,你是XXX
    戏说Android view 工作流程《下》
    “燕子”
    Android开机动画bootanimation.zip
    戏说Android view 工作流程《上》
    ViewController里已连接的IBOutlet为什么会是nil
    My first App "Encrypt Wheel" is Ready to Download!
    iOS开发中角色Role所产生的悲剧(未完)
    UIScrollView实现不全屏分页的小技巧
    Apple misunderstood my app,now my app status changed to “In Review”
  • 原文地址:https://www.cnblogs.com/lobtao/p/1501716.html
Copyright © 2011-2022 走看看