替换ASP.NET C#中的函数 [英] Replace function in asp.net c#

查看:85
本文介绍了替换ASP.NET C#中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net网站上.

替换功能有问题

我的代码是

In my asp.net website .

there is a problem with replace function

my code is

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

           string Gp = lblCategory_Name.Text.ToString().Replace("'", "");
           Gp = Gp.ToString().Replace(" ", "");
XmlNode newXMLNode = xmlDoc.SelectSingleNode("/gallery/category[contains(@name,'" + Gp + "')]");
           XmlNode childnode = xmlDoc.CreateNode(XmlNodeType.Element, "image", "");



替换功能工作后," newXMLNode "将获得空值.
任何人都可以帮助我



After Replace funtion working ''newXMLNode'' get null value .
Any one pls help me

推荐答案

首先,这完全可以正常工作:
First of all, this works perfectly fine:
Label1.Text = "Sandeep'Mewara  is a soft'ware engine'er  so'me where.";
string Gp = Label1.Text.ToString().Replace("'", "");
Gp = Gp.ToString().Replace(" ", "");



其次,您无需将Gp强制转换回字符串,因为它已经是字符串.以下是您所需要的:



Secondly, you don''t need to cast Gp back to string as it is already a string. Following is all you need:

Label1.Text = "Sandeep'Mewara  is a soft'ware engine'er  so'me where.";
string Gp = Label1.Text.ToString().Replace("'", "");
Gp = Gp.Replace(" ", "");




输出:"SandeepMewaraisasoftwareengineersomewhere."

确保您的标签传递了正确的文本.使用Visual Studio DEBUGGER查看问题所在和出处.




Output: "SandeepMewaraisasoftwareengineersomewhere."

Make sure your label has proper text passed. Use Visual studio DEBUGGER to see what and where you are going wrong.


这篇关于替换ASP.NET C#中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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