[英]vb.net string replace aspx
Trying to replace a string when a user clicks a button. 当用户单击按钮时尝试替换字符串。 Replace has worked so far but can't get it to work this time.
到目前为止,Replace一直有效,但是这次无法正常工作。
I have a protected variable, tPage in my class which stores a html page. 我的类中有一个受保护的变量tPage,用于存储html页面。
Basically I have a asp input field like so: 基本上我有一个asp输入字段,如下所示:
<input type='hidden' name='hiredate' style='height:50px; width: 49%; border:0px solid; float:right;' />
(please ignore the inline css, it will be removed later) (请忽略内联CSS,稍后将其删除)
The page that holds the input is fed into a string variable and accessed later in order to un-hide the input at a later time. 保存输入的页面被馈送到字符串变量中,并在以后访问,以便在以后取消隐藏输入。
I've tried using the replace function like so: 我试过像这样使用replace函数:
tPage &= "<input type='hidden' name='hiresign'".Replace("'hidden'", "'text'")
but when the code runs there is no change to the string. 但是当代码运行时,字符串没有变化。
**Edit **编辑
I found a solution with your guidance. 我在您的指导下找到了解决方案。 I changed the code to:
我将代码更改为:
tPage = tPage.Replace("<input type='hidden' name='hiresign'", "<input type='text' name='hiresign'")
&=
将一个字符串连接到另一个字符串,您要替换该字符串:
tPage = "<input type='hidden' name='hiresign'".Replace("'hidden'", "'text'")
Try this 尝试这个
Dim str = "<input type='hidden' name='hiresign'"
str = str.Replace("'hidden'", "'text'")
tPage &= str
The point is &= will concats the string in tPage and because of that you are not getting the replaced values corrctly. 关键是&=将在tPage中连接该字符串,因此您无法正确获取替换后的值。 You have to first do the Replcae and then assign the value in tPage.
您必须首先执行Replcae,然后在tPage中分配值。 Hope this helps.
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.