Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]", "");
C#
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
Posted
Comments
Manfred Rudolf Bihy 24-Sep-14 7:03am    
Well you almost had it right.
Except that this: href = Regex.Replace(href, "[^a-zA-Z]", "");
Should read like this: href = Regex.Replace(href, "[^0-9]", "");

Anything NOT zero through nine should be replaced by "".

Cheers!
miss786 24-Sep-14 7:09am    
Many thanks for explaining the logic. This mistake will not happen again.

C#
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.
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 24-Sep-14 7:06am    
That will also do! 5+
Thanks7872 24-Sep-14 7:20am    
Thanks Manfred...
miss786 24-Sep-14 7:08am    
Thats amazing. Many thanks for your great help. :)
Thanks7872 24-Sep-14 7:19am    
Glad to help you...Enjoy
KaushalJB 24-Sep-14 7:41am    
Yeah also worked for me :)
test="Tage (5174102)";

string str = Regex.Match(text, @"\d+").Value;

from this you will get 5174102
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900