在Text中如何让输入 的 +  变成了 + 呢 ???

解决方案 »

  1.   

    这是我曾经做过的一个程序,也是用某一字符来替换指定的字符
    unit UnitMain;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TFrmMain = class(TForm)
        Button1: TButton;
        OpenDialog: TOpenDialog;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        StrFlieName:String;
      end;var
      FrmMain: TFrmMain;implementationuses UnitTextFile;{$R *.dfm}
    function StrTran(psInput:String; psSearch:String; psTranWith:String):String;
    var
    liPosition,liLenOfSrch,liLenOfIn:integer;
    begin
    liPosition:=Pos(psSearch,psInput);
    liLenOfSrch:=Length(psSearch);
    liLenOfIn:=Length(psInput);
    while liPosition>0 do
    begin
    psInput:=Copy(psInput,1,liPosition-1)
    +psTranWith
          +Copy(psInput,liPosition+liLenOfSrch,liLenOfIn);
    liPosition:=Pos(psSearch,psInput)
    end;
    Result:=psInput
    end;
    procedure TFrmMain.Button1Click(Sender: TObject);
    var textcontent:TStringList;
    begin
    OpenDialog.Options:=ofAllowMultiSelec;
    OpenDialog.Execute;
    if OpenDialog.FileName='' then
      exit;
    textcontent:= TStringList.create;
    textcontent.LoadFromFile(OpenDialog.FileName);
    textcontent.Text:=StrTran(textcontent.Text,'Label,','标签, ');
    textcontent.Text:=StrTran(textcontent.Text,'LABEL,','标签, ');
    textcontent.SaveToFile(OpenDialog.FileName);
    end;end.
    但是如果你是要在控件输入时来控制的话,可以在该控件的KEYPRESS事件中,进行这样处理,
    procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
    if ord(key)=22 then
       key:='+';
    end;   //"+"的ASCII码时22
      

  2.   

    OnChange事件中使用StrReplace函数……
      

  3.   

    1、把string转换成wideString
    2、使用WideString的字符替换函数。其实,使用AnsiString的替换函数也没问题,但是替换的时候可能造成误解,把其他双字节文字的第二个字符等于'+'的给替换了。所以,处理汉字字符串最稳妥地办法就是转换成Unicode字符串处理。我这么一说,大家应该明白楼主的本义了吧。