edrp.cn的Blog

学习,需要交流,欢迎大家和我共同来学习C#,ASP.NET,MS SQL Server开发Web项目,欢迎大家和我交流

博客园 首页 新随笔 联系 订阅 管理
const
// Special symbols
  _TAB_   = #9;
  _CR_    = #13;
  _NL_    = #10;
  _DELIM_ = ' :;.,+-<>/*%^=()[]|&~@#\`{}'+_TAB_;
  _SPACE_ = ' ';
 
// Convert string to C-escape string format
function ConvStr(Value: String): String;
var I: Integer;
begin
 
  Result := '';
  for I := 1 to Length(Value) do begin
    case Value[I] of
      #34: Result := Result + '\' + #34;
      #39: Result := Result + '\' + #39;
      _TAB_: Result := Result + '\t';
      _NL_: begin end;
      _CR_: Result := Result + '\n';
      '\': Result := Result + '\\';
      else Result := Result + Value[I];
    end;
  end;
end;
 
// Convert string from C-escape string format
function UnconvStr(Value: String): String;
var I: Integer;
begin
  Result := '';
  I := 1;
  while I<=Length(Value) do begin
    if Value[I]='\' then begin
      if I=Length(Value) then break;
      Inc(I);
      case Value[I] of
        'n': Result := Result + _CR_;
        't': Result := Result + _TAB_
        else Result := Result + Value[I];
      end;
    end else Result := Result + Value[I];
    Inc(I);
  end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo2.Text:=ConvStr(Memo1.Text);
end;
 
procedure TForm1.Button2Click(Sender: TObject);
begin
Memo2.Text:=UnconvStr(Memo1.Text);
end;
 
代码来自网络
posted on 2022-08-17 13:50  edrp.cn  阅读(14)  评论(0编辑  收藏  举报