Left(ShortMsg,10)这样只能截取前10个字,怎么去掉shortmsg中的回车符呢?我指的是同时使用left和replace

解决方案 »

  1.   

    DECLARE @ShortMsg VARCHAR(20)
    SET @ShortMsg='ASDFSD
    SDFSDF'SELECT @ShortMsg
    /*
    -------------------- 
    ASDFSD
    SDFSDF
    */
    SELECT REPLACE(REPLACE(@ShortMsg,CHAR(13),''),CHAR(10),'')
    /*
    ASDFSDSDFSDF
    */
      

  2.   


    SELECT left(REPLACE(REPLACE(@ShortMsg,CHAR(13),''),CHAR(10),''),10)
      

  3.   


    declare @str varchar(1000)
    set @str='abcdefdafswaa
    ghj'
    select left(replace(replace(@str,char(10),''),char(13),''),10)
      

  4.   

    还是没有答案```   .net页面上怎么用
      

  5.   


    --数据库层:
    DECLARE @str nvarchar(88) 
    SET @str=N'师傅,
    我终于学会做鸡肉炖蘑菇啦!!!' select left(replace(@str,char(13)+char(10),''),10)
    /*
    ------------------------------
    师傅,我终于学会做鸡
    */
    //页面上:
    string s="师傅,\r\n我终于学会做鸡肉炖蘑菇啦!!!";
    s = s.Replace("\r", "").Replace("\n", "").Substring(0,10);
    Response.Write("<script language=javascript>alert('"+s+"');</script>");---------------------------
    Windows Internet Explorer
    ---------------------------
    师傅,我终于学会做鸡
    ---------------------------
    OK   
    ---------------------------