替换字符串函数 [英] replace string function
本文介绍了替换字符串函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从以下字符串中删除方括号()和名称tag:标记(5174102)
这是我正在使用的但是当我添加以下代码行,我得到一个空白页/ null。因此,我可以,到目前为止删除标签字符串。
href = Regex.Replace(href,[^ a-zA-Z],) ;
I am trying to remove brackets () and name "tag", from the following string: Tag (5174102)
This is what I am using but when I add the following line of code , I get a blank page/null. Hence , I can, so far remove the "tag" string.
href = Regex.Replace(href, "[^a-zA-Z]", "");
public static string readUri2()
{
string uri = "";
var document = XDocument.Parse(WRequest());
var href = document.Descendants("link").Single().Attribute("title").Value;
href = href.Replace("Tag", "");
href = Regex.Replace(href, "[^a-zA-Z]", "");
return uri = href.ToString();
}
我想要的输出是获取,只有上面字符串中的数字。
如有任何提示,请问如何实现这一目标。非常感谢
My desired output is to get, only the number from the above string.
Any hints in, how can I achieve this, please. Many thanks
推荐答案
string Test = "Tag (5174102)";
string Your_Desired_String = Regex.Match(Test, @"\d+").Value;//This will be 5174102. That is, no 'Tag'/Brackets
如果它不能按你想要的方式工作,请告诉我。
Let me know if it doesn't work the way you want.
test =Tage(5174102);
string str = Regex.Match(text,@\d + )。价值;
从此您将获得5174102
test="Tage (5174102)";
string str = Regex.Match(text, @"\d+").Value;
from this you will get 5174102
这篇关于替换字符串函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文