如何在不使用asp.net中的字符串功能的情况下从字符串中删除撇号 [英] How to remove apostrophe from a string without using string function in asp.net

查看:98
本文介绍了如何在不使用asp.net中的字符串功能的情况下从字符串中删除撇号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不使用asp.net c#中的字符串功能的情况下从字符串中删除撇号c#

我的代码如下.

我在newXMLNode中得到了空值,使用了任何字符串函数来替换apptrophe.
我想更换贴心

How to remove apostrophe from a string without using string function in asp.net c#

My code is given below.

I got null value in newXMLNode sfter use any string function fro to replace appstrophe .
i want to replace appostrophe

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(Server.MapPath("~/gallery/gallery.xml"));

XmlNode newXMLNode;
 
           XmlNode node2 = xmlDoc.DocumentElement;

 
newXMLNode = node2.SelectSingleNode("/gallery/category[contains(@name,'" + str + "')]");


请帮助我.


Pls help me.

推荐答案

尝试一下:
Try this:
char sep = (str.Contains("'"[0])) ? '"': '\'';
string xpathQuery = "/gallery/category[contains(@name," + sep + str + sep + ")]"; 
newXMLNode = node2.SelectSingleNode(xpathQuery );


这意味着:


  • 如果字符串中包含单引号,请在查询中使用双引号.
  • 否则,请在查询中使用单引号.

  • This means:


    • If your string has a single quote in it, use double quotes inside your query.
    • Otherwise, use single quotes inside your query.

    • 这篇关于如何在不使用asp.net中的字符串功能的情况下从字符串中删除撇号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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