Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Trying to strip all special characters from a string by using the following:
using System.Text.RegularExpressions; string your_String = CurrentPage.description; string my_String = Regex.Replace(your_String, @"[^0-9a-zA-Z]+", ",");
unfortunately I get the following error:
The best overloaded method match for system.text.regularexpresions.regex.replace(string,string)' has some invalid arguments. Any suggestions?
Hi Jeff
It's because you're passing 3 parameters but the the method only accepts two as the error message is also indicating.
You can see some examples on how to use Regex.Replace here https://msdn.microsoft.com/en-us/library/xwewhkd1%28v=vs.110%29.aspx
You should be able to do something like
string pattern = @"[^0-9a-zA-Z]+"; string input = CurrentPage.description; string replacement = ""; Regex rgx = new Regex(pattern); string result = rgx.Replace(input, replacement) //Write out the result @result
Hope this helps.
/Jan
Thanks Jan
This is what I ended up using for anyone else that would need this.
string pattern = @"[^\w\.@:-]"; string input = Umbraco.StripHtml(CurrentPage.description).ToString(); string replacement = " "; Regex rgx = new Regex(pattern); string result = rgx.Replace(input, replacement);
Happy I could help - Remember to mark the issue as solved so others can jump straight to the solution if they come across the same issue.
Happy coding!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
removing special characters from string
Trying to strip all special characters from a string by using the following:
unfortunately I get the following error:
The best overloaded method match for system.text.regularexpresions.regex.replace(string,string)' has some invalid arguments. Any suggestions?
Hi Jeff
It's because you're passing 3 parameters but the the method only accepts two as the error message is also indicating.
You can see some examples on how to use Regex.Replace here https://msdn.microsoft.com/en-us/library/xwewhkd1%28v=vs.110%29.aspx
You should be able to do something like
Hope this helps.
/Jan
Thanks Jan
This is what I ended up using for anyone else that would need this.
Hi Jeff
Happy I could help - Remember to mark the issue as solved so others can jump straight to the solution if they come across the same issue.
Happy coding!
/Jan
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.