拆分漢字字串

來源:互聯網
上載者:User
拆分漢字字串 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分吧  
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.