FlorenceYee
asked on
Help! Something isn't right with this code!!
string ImaxName;
xName = Request.PathInfo;
xName = Regex.Replace(xName, "\", "");
xName = Regex.Replace(xName, "/", "");
I'm trying to replace / and \ in the xName string. But since i'm new to this language, what escape character should i use??!!
xName = Request.PathInfo;
xName = Regex.Replace(xName, "\", "");
xName = Regex.Replace(xName, "/", "");
I'm trying to replace / and \ in the xName string. But since i'm new to this language, what escape character should i use??!!
A regex is a complex pattern matching engine, and writing patterns needs some knowledge about Regex patterns. You will not need to use two regex to replace these chars in any case. In fact, you have two better possibilities:
* Use string.Replace() instead of Regex.Replace():
string xName;
xName = Request.PathInfo.Replace(@ "\", "").Replace("/", "");
* Use just ONE regex to match both patterns to replace:
string xName;
xName = Regex.Replace(Request.Path Info, @"\\|/", "");
* Use string.Replace() instead of Regex.Replace():
string xName;
xName = Request.PathInfo.Replace(@
* Use just ONE regex to match both patterns to replace:
string xName;
xName = Regex.Replace(Request.Path
ASKER
can anyone tell me how do:
Private Sub Abc() in C# or:
Private Function Abc(xyz) in C#?
I'm very new to C family of language.
Private Sub Abc() in C# or:
Private Function Abc(xyz) in C#?
I'm very new to C family of language.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Please do not ask multiple questions in one question.
FlorenceYee, it was not correct of you to accept smeggheads second comment as answer for two reasons:
* The answer you accepted has no relation whatsoever to the original question.
* The first comment by smegghead is not correct and would NOT work. Try it if you don't believe me. My comment, however, does present two possibilities to achieve what you asked - in a 30 point question, which is almost the minimum.
I don't care about the 30 points, but I do care about people who don't care. There are certain rules you have accepted when you joined Experts Exchange, one of them being not to ask several different questions in the same question. The other is to carefully consider the grading.
(Smegghead, the regex engine also uses \ to escape special chars, so that @"\\" or "\\\\" must be used as string in this situation.)
* The answer you accepted has no relation whatsoever to the original question.
* The first comment by smegghead is not correct and would NOT work. Try it if you don't believe me. My comment, however, does present two possibilities to achieve what you asked - in a 30 point question, which is almost the minimum.
I don't care about the 30 points, but I do care about people who don't care. There are certain rules you have accepted when you joined Experts Exchange, one of them being not to ask several different questions in the same question. The other is to carefully consider the grading.
(Smegghead, the regex engine also uses \ to escape special chars, so that @"\\" or "\\\\" must be used as string in this situation.)
i.e.
xName = Regex.Replace(xName, @"\", "");