如题,其实目的就是将回车符去掉

解决方案 »

  1.   

    var
      i : Integer;
      str : String;
    begin
      for i := 0 to RichEdit.lines.count -1 do 
        begin
          str := str + RichEdit.lines.String[i]; 
          RichEdit.lines.delete(i);
        end; 
      richedit1.Lines.add(str);
    end;
      

  2.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
      i : Integer;
      str : String;
    begin
      for i := RichEdit1.lines.count -1 downto 0 do
      begin
        str := str + RichEdit1.lines.Strings[i];
        RichEdit1.lines.delete(i);
      end;
      richedit1.Lines.Add(str);
    end;
      

  3.   

    如果加载到RichEdit文件的格式一样的,下面的代码就可以;
    procedure TFormRTF.Button13Click(Sender: TObject);
    var
      i : Integer;
      str : String;
      taStyle: TTextAttributes;
    begin
      RichEdit1.SelectAll;
      taStyle := RichEdit1.SelAttributes;
      for i := RichEdit1.lines.count -1 downto 0 do
      begin
        str := str + RichEdit1.lines.Strings[i];
        RichEdit1.lines.delete(i);
      end;
      richedit1.Lines.Add(str);
      RichEdit1.SelectAll;
      RichEdit1.SelAttributes := taStyle;
    end;
    如果每行的格式不同,则按下面的步骤:
    (1)逐行选择,利用RichEdit的SelStart,SelLength,SelText属性;
    (2)保存选择内容的TextAttributes;
    (3)把选择的内容合并到相应的行;
    (4)用之前保存的TextAttributes设置合并内容的TextAttributes;
      

  4.   


    RichEdit.lines.text := stringreplace(RichEdit.lines.text, #13#10, '', [rfReplaceAll]);
      

  5.   

    function TForm1.SingleLine: string;
    var
      pStr: PChar;
      i, j, iLen: Integer;
      Str: string;
    begin
      for i := 0 to redt2.Lines.Count - 1 do
      begin
        Str := Str + redt2.Lines.Strings[i];
      end;
      redt2.Clear;
      redt2.Lines.Add(str);  pStr := @redt1.Text[1];
      iLen := Length(redt1.Text);
      i := 0;
      j := 0;
      if pStr <> nil then
      begin
        while i < iLen  do
        begin
          redt1.SelStart := i;
          redt1.SelLength := 1;
          if (pStr[i] <> #13) and (redt1.SelText <> '')then
          begin
            redt2.SelStart := j;
            redt2.SelLength := 1;
            if redt1.SelText <> redt2.SelText then
            begin
              i := i - 1;
              while redt1.SelText <> redt2.SelText do
              begin
                redt1.SelStart := i;
                redt1.SelLength := 1;
                if redt1.SelText = redt2.SelText then
                  Break;
                Inc(i);
              end;
            end;        redt2.SelStart := j;
            redt2.SelLength := 1;
            redt2.SelAttributes := redt1.SelAttributes;        Inc(j);
          end
          else
          begin
            mmo1.Lines.Add(#10#13);
          end;
          Inc(i);
        end;
      end;
    end;
      

  6.   

    就是设置起点,选择字符的长度(终点),然后设置这些字符的属性即用下面3个属性就OK了
    SelStart,SelLength,SelAttributes
      

  7.   

    procedure TForm1.DelReturnCharacter;
    var
      pStr: PChar;
      i, j, iLen: Integer;
      Str: string;
      RichTextAttributes: array[0..1024] of TRichTextAttributes;
    begin
      pStr := @redt2.Text[1];
      iLen := Length(redt2.Text);
      for i := 0 to iLen do
      begin
        StrPCopy(RichTextAttributes[i].Text, pStr[i]);
        redt2.SelStart := i;
        redt2.SelLength := 1;
        RichTextAttributes[i].taStyle := redt2.SelAttributes;
      end;  for i := 0 to redt2.Lines.Count - 1 do
      begin
        Str := Str + redt2.Lines.Strings[i];
      end;
      redt2.Clear;
      redt2.Lines.Add(str);  i := 0;
      j := 0;
      while i < iLen  do
      begin
        if (RichTextAttributes[i].Text[0] <> #13) and (RichTextAttributes[i].Text <> '')then
        begin
          redt2.SelStart := j;
          redt2.SelLength := 1;
          if RichTextAttributes[i].Text <> redt2.SelText then
          begin
            i := i - 1;
            while RichTextAttributes[i].Text <> redt2.SelText do
            begin
              if RichTextAttributes[i].Text = redt2.SelText then
                Break;
              Inc(i);
            end;
          end;      redt2.SelStart := j;
          redt2.SelLength := 1;
          redt2.SelAttributes := RichTextAttributes[i].taStyle;      Inc(j);
        end
        else
        begin
          mmo1.Lines.Add(#10#13);
        end;
        Inc(i);
      end;
    end;
      

  8.   

    各位,不好意思,因现在做的项目用到此方面的功能,第一次发的代码,是用二个RichEdit控件来保存样式,第二次发的,是用一个RichEdit就行