var
  strMy : string;
begin
  srtMy := 'This is my code.';
end;在输出的时候,在屏幕上显示的是: This is my code.
但是现在我想在屏幕上显示的是: 'This is my code'. //头和尾都多一个单引号
请问该怎么实现呢?
谢谢(只有10分了,实在不好意思)

解决方案 »

  1.   

    var
      strMy : string;
    begin
      srtMy := '''This is my code.''';
    end;
      

  2.   

    Delphi(应该说是Pascal)的语法中规定,在字符串常量中是用连续两个单引号来表示一个单引号字符的。所以,
    要表示 'This is my code' 这样一串字符,应该写成 '''This is my code'''。
    要表示一个单引号,则写成 ''''。
      

  3.   

    我现在是想写一个sql语句,是插如数据库的: 
    insert 
    into MyTable
    values ('Edit1.Text'); 但是在ADOQuery里面怎么写呢?
    我是这么写的
    ADOQuery1.SQL.Text := 'insert into MyTable values =(' '''Edit1.Text'''')';
    总是不对,想求一正确的写法,谢谢
      

  4.   

    第一个问题:
        srtMy:= char(39)+'This is my code.'+char(39);第二个问题:   ADOQuery1.SQL.Text := 'insert into MyTable values('+Quotedstr(Edit1.Text)+')';
    char(39)...char(39) 和 Quotedstr 都是代表一对单引号哈,不要用''''容易出错
      

  5.   

    楼主不要受楼主的误导哦。ADOQuery1.SQL.Text := 'insert into MyTable values =(''' +  Edit1.Text + ''')';如果非要象孔乙已一样说回字有几种写法的话,那么:srtMy:= '''This is my code.''';srtMy:= #39'This is my code.'#39;srtMy:= chr(39)+'This is my code.'+chr(39);srtMy:= char(39)+'This is my code.'+char(39);注:这四两种写法,编译器编译生成的代码是一样的。
      

  6.   

    楼主不要受楼上的误导哦。ADOQuery1.SQL.Text := 'insert into MyTable values =(''' +  Edit1.Text + ''')';如果非要象孔乙已一样说回字有几种写法的话,那么:srtMy:= '''This is my code.''';srtMy:= #39'This is my code.'#39;srtMy:= chr(39)+'This is my code.'+chr(39);srtMy:= char(39)+'This is my code.'+char(39);注:这四两种写法,编译器编译生成的代码是一样的。
      

  7.   

    呵呵,chb5210(沉默)推荐用Quotedstr的意思可能是说单引号多了容易看得头晕,不便于查错
      

  8.   

    cuteant(我这张旧船票还能否登上你的破船|涛声是否依旧) 
    啊~~~~~~~~~`遇到知音了^-^