如一句经过标注的话:筐/n  里/f  装满/v  了/u  各式各样/l  的/u  水果/n  ,/w  有/v  梨/n  、/w  苹果/n  、/w  桔子/n  、/w  ....../w  令/v  我/r  眼花缭乱/i  。/w   
顿号应该去掉,请问如何用Delphi实现? 
代码如何写? 急用
谢谢。

解决方案 »

  1.   

    类似代码如下var
      s,str:string;
      i,len:integer;
    begin
      s:='筐/n  里/f  装满/v  了/u  各式各样/l  的/u  水果/n  ,/w  有/v  梨/n  、/w  苹果/n  、/w  桔子/n  、/w  ....../w  令/v  我/r';
      while s<>'' do
      begin
        i:=pos('、',s);
        if i=0 then
        beign
          s:=''
          str:=str+s;
        end
        else
        begin
          s:=copy(s,i+2,length(s)-(i+2)+1);
          str:=str+copy(s,1,i-1);
        end;
      end;
      showmessage(str);
    end;
      

  2.   

    StringReplace(s, '、', ' ', [rfReplaceAll]);
      

  3.   

    还是需要对字符串遍历,可以使用类似的代码
    var
      str:widestring;
    begin
      i:=length(str);
      for j:=1 to i do
      begin
        if (str[j]=',') and (j<>1) and (j<>i) then
        begin
          if ((str[j-1]<>'“') or (str[j-1]<>'”')) and ((str[j+1]<>'“') or (str[j+1]<>'”')) then
          begin
            showmessage('此处的逗号使用错误');
            //因为不知道你是怎么显示这段文字的,所以对于用红色表示错误标点,无法给出相应代码,你可以说明你用什么显示文字
          end;
        end;
      end;
    end;
      

  4.   

    还有一个问题,我试了你给的代码,编译是没有错的,可是没有标红。你帮我看看哪里错了可以吗?再次谢谢你,我真是不明白。
    procedure TForm1.Button2Click(Sender: TObject);
    var
     i,j: integer ;
     str:widestring ;
     begin
     i:=length(str);
     for j:=1 to i do
        begin
         if(str[j]=',')and(j<>1)and(j<>i) then
           begin
             if ((str[j-1]<>'”')or(str[j-1]<>'“'))and(( str[j+1]<>'”')or(str[j+1]<>'“'))
             then
             begin
            RichEdit1.SelStart:= 46;            //从第46个字符开始
             RichEdit1.SelLength:= 4;                 //长度
             RichEdit1.SelAttributes.Color:=clRed;   //标红
            end;
           end;
        end;end;
      

  5.   

    你根本没给str赋值啊
    应该在开始加上str:=self.RichEdit1.Lines.Text;
      

  6.   

    这是我改进过的代码,我测试过了procedure TForm1.Button1Click(Sender: TObject);
    var
    i,j,len: integer ;
    str:widestring ;
    s,s1,s2:string;
    begin
      str:=self.RichEdit1.Lines.Text;
      i:=length(str);
      len:=0;
      for j:=1 to i do
      begin
        s:=str[j];
        len:=len+length(s);
        if(str[j]=',')and(j <>1)and(j <>i) then
        begin
          s1:=str[j-1];
          s2:=str[j+1];
          if ((s1='”') or (s1 ='“')) and (( s2 ='”') or (s2 ='“')) then
          else
          begin
            RichEdit1.SelStart:= len-length(s);            //从第46个字符开始
            RichEdit1.SelLength:= length(str[j]);                //长度
            RichEdit1.SelAttributes.Color:=clRed;  //标红
          end;
        end;
      end;
    end;
      

  7.   

    还是不行,我都要疯了,这是我的全部代码,麻烦你最后帮我看一下吧unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        OpenDialog1: TOpenDialog;
        richedit1: TRichEdit;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
       
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      str:string ;
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      if opendialog1.execute then
        begin
        richedit1.Lines.LoadFromFile(opendialog1.filename);
        str:=RichEdit1.Text;
        end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
     i,j,len: integer ;
     str:widestring ;
     s,s1,s2:string;
     begin
     str:=RichEdit1.Text;
     i:=length(str);
     len:=0;
     for j:=1 to i do
        begin
         if(str[j]=',')and(j<>1)and(j<>i) then
           begin
           s1:=str[j-1];
           s2:=str[j+1];
            if ((s1='”') or (s1 ='“')) and (( s2 ='”') or (s2 ='“'))
            then
              begin
            RichEdit1.SelStart:= len-length(s);                        
            RichEdit1.SelLength:= length(str[j]);                                
            RichEdit1.SelAttributes.Color:=clRed;   
             end;
           end;
        end;end;end.
      

  8.   

    是全局变量的事吧
    str你已经定义为全局变量
    在button2的onclick事件中又定义了str变量
      

  9.   

    unit Unit1; interface uses 
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
      Dialogs, StdCtrls, ComCtrls; type 
      TForm1 = class(TForm) 
        Button1: TButton; 
        Button2: TButton; 
        OpenDialog1: TOpenDialog; 
        richedit1: TRichEdit; 
        procedure Button1Click(Sender: TObject); 
        procedure Button2Click(Sender: TObject); 
      
      private 
        { Private declarations } 
      public 
        { Public declarations } 
      end; var 
      Form1: TForm1; 
      str:string ; 
    implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); 
    begin 
      if opendialog1.execute then 
        begin 
        richedit1.Lines.LoadFromFile(opendialog1.filename); 
        str:=RichEdit1.Text; 
        end; 
    end; 
    procedure TForm1.Button2Click(Sender: TObject); 
    var 
    i,j,len: integer ; 
    str:widestring ; 
    s,s1,s2:string; 
    begin 
    str:=RichEdit1.Text; 
    i:=length(str); 
    len:=0; 
    for j:=1 to i do 
    begin 
        s:=str[j];
        len:=len+length(s);    if(str[j]=',')and(j <>1)and(j <>i) then 
          begin 
          s1:=str[j-1]; 
          s2:=str[j+1]; 
            if ((s1='”') or (s1 ='“')) and (( s2 ='”') or (s2 ='“')) 
            then 
              begin 
            RichEdit1.SelStart:= len-length(s);                        
            RichEdit1.SelLength:= length(str[j]);                                
            RichEdit1.SelAttributes.Color:=clRed;  
            end; 
          end; 
        end; end; end.
      

  10.   

    兄弟應該把分都給 lovelymelon  了,人家的代碼給你貼好了,結果你自己弄錯了。呵呵
      

  11.   

    1. 筐/n  里/f  装满/v  了/u  各式各样/l  的/u  水果/n ,/w ,/w  有/v  梨/n  、/w  苹果/n  、/w  桔子/n  、/w  ....../w  令/v  我/r  眼花缭乱/i  。/w  
      

  12.   

    1.需要结贴才能给分的
    2.筐/n  里/f  装满/v  了/u  各式各样/l  的/u  水果/n ,/w ,/w  有/v  梨/n  、/w  苹果/n  、/w  桔子/n  、/w  ....../w  令/v  我/r  眼花缭乱/i  。/w是什么意思?你richedit中显示的内容?/v,/w之类的就是这样显示的,还是需要转译?
      

  13.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        OpenDialog1: TOpenDialog;
        richedit1: TRichEdit;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);  private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      str:widestring ;
    implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      if opendialog1.execute then
        begin
        richedit1.Lines.LoadFromFile(opendialog1.filename);
        str:=RichEdit1.Text;
        end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
     i,j,len: integer ;
     s,s1,s2:string;
     begin
     i:=length(str);
     len:=0;
     for j:=1 to i do
        begin
         if(str[j]=',')and(j<>1)and(j<>i) then
           begin
           s1:=str[j-1];
           s2:=str[j+1];
            if ((s1='”') or (s1 ='“')) and (( s2 ='”') or (s2 ='“'))
            then
              begin
            RichEdit1.SelStart:= len-length(s);                              //从第三个字符开始
            RichEdit1.SelLength:= length(str[j]);                                   //长度
            RichEdit1.SelAttributes.Color:=clRed;   //标红
             end;
           end;
        end;
    end;
    end.文件内容就是1. 筐/n  里/f  装满/v  了/u  各式各样/l  的/u  水果/n ,/w ,/w  有/v  梨/n  、/w  苹果/n  、/w  桔子/n  、/w  ....../w  令/v  我/r  眼花缭乱/i  。/w  
      

  14.   

    第一步:用StringReplace函数将所有 , 替换为红色 , 第二步:用StringReplace函数将所有 ”, 替换为 ”, 第三步:用StringReplace函数将所有 ,“替换为 ,“ 这样效率可能不是最高,但最方便。