delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
拆分汉字字符串 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061202180701129.html
比如有一字符串    
  s:=‘真的好喜欢你’;  
  现在要把他分成  
  array     f[0]:=‘真’;  
                f[1]:='的   ';  
                ...........  
                f[5]:='你';  
  能写出详细的过程吗   有分的哦

var  
      Idx:   Integer;  
      Str:   String;  
      Arr:   array   of   WideString;  
      Len:   Integer;  
  begin  
      Len   :=   0;  
      Str   :=   'I我LOVE爱YOU你';  
      for   Idx   :=   0   to   Length(WideString(Str))   do  
      begin  
          if   Ord(WideString(Str)[Idx])   >=   $1000   then  
          begin  
              Inc(Len);  
              SetLength(Arr,   Len);  
              Arr[Pred(Len)]   :=   WideString(Str)[Idx];  
          end;  
      end;  
  end;

var  
      str:string;  
      arr:array[0..6]   of   string;  
      I,J:integer;  
  begin  
      str:='我真的好喜欢你';  
      J:=1;  
      for   I   :=   0   to   6   do  
              begin  
              arr[I]:=str[J]+str[J+1];  
              inc(J,2);  
              end;  
      for   I:=0   to   6   do  
      //edit1.Text:=edit1.Text+arr[I];  
  end;

var  
  f,g:string;  
  i,j,k:integer;  
  begin  
  g:='喜欢你';  
  j:=length(g);  
  for   i:=1   to   j   do  
  begin  
  if   (i   mod   2   <>   0   )   then  
  begin  
  f:=midstr(g,i,2);  
  showmessage(f);  
  //showmessage(inttostr(i));  
    end;  
  end;  
  end;  
   
  扼   我自己也想了一个出来     又学到了  
  哈哈       每人25分吧  
 

posted on 2008-09-23 09:37 delphi2007 阅读(284) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。