如何删除由scriptmanager使用的字符串弹出的标点符号 [英] how to remove punctuation of string pop up using by scriptmanager

查看:76
本文介绍了如何删除由scriptmanager使用的字符串弹出的标点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我有一个像你好,你怎么样的字符串。当这个字符串出现并在scriptmanager中用于弹出时它将无法工作。



但是当我从字符串中删除`s以便它可以正常运行。



所以,我怎么能解决这个问题。



我的代码:



 string s =select think from think_of_month; 
SqlDataAdapter ad = new SqlDataAdapter(s,c.getcon());
DataSet ds = new DataSet();
ad.Fill(ds);

if(ds.Tables [0] .Rows.Count!= 0)
{
thought = ds.Tables [0] .Rows [0] [0]。的ToString();
// thought =你好;
try
{

ScriptManager.RegisterStartupScript(this,this.GetType(),alert,alert(''+ convertQuotes(ds.Tables [0]。行[0] [0] .ToString())+''); window.location =''User_Home.aspx'';,true);
}
catch(例外e1)
{
e1.Message.ToString();
}
-----------

public string convertQuotes(string str)
{
return str.Replace( '',''''');
}





请帮帮我......



谢谢和问候....

Mitesh

解决方案

尝试转义序列:

  public   string  convertQuotes( string  str)
{
return str.Replace( ' \');
}



参考: MSDN:转义序列 [ ^ ]


Dear All,

I have a string like "Hello how`s you". when this string is come and used in scriptmanager for pop up it will not work.

but when i remove the "`s" from string so it works perfact.

so, how can i resolved this problm.

my code:

  string s = "select thought from thought_of_month";
            SqlDataAdapter ad = new SqlDataAdapter(s, c.getcon());
            DataSet ds = new DataSet();
            ad.Fill(ds);

            if (ds.Tables[0].Rows.Count != 0)
            {
                thought = ds.Tables[0].Rows[0][0].ToString();
                //thought = "hello";
                try
                {
                    
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert(''" + convertQuotes(ds.Tables[0].Rows[0][0].ToString()) + "'');window.location =''User_Home.aspx'';", true);
                }
                catch (Exception e1)
                {
                    e1.Message.ToString();
                }
-----------

 public string convertQuotes(string str)
    {
        return str.Replace("''", "''''");
    }



please help me......

Thanks and Regards....
Mitesh

解决方案

Try escape sequence:

public string convertQuotes(string str)
{
   return str.Replace("'", "\'");
}


Refer: MSDN: Escape Sequences[^]


这篇关于如何删除由scriptmanager使用的字符串弹出的标点符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆