Help! Something isn't right with this code!!

Posted on 2003-03-14
Medium Priority
Last Modified: 2010-04-15
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??!!
Question by:FlorenceYee
  • 3
  • 2
LVL 10

Expert Comment

ID: 8143057
put a @ infront of the string


xName = Regex.Replace(xName, @"\", "");
LVL 14

Expert Comment

ID: 8145820
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.PathInfo, @"\\|/", "");

Author Comment

ID: 8155183
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.
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 10

Accepted Solution

smegghead earned 120 total points
ID: 8157893
private void Abc()
  // your code goes here (void tells the compiler that we're not returning a value - same as 'sub')

private int Abc()
  // your code goes here
  return MyInt;
LVL 14

Expert Comment

ID: 8158731
Please do not ask multiple questions in one question.
LVL 14

Expert Comment

ID: 8220134
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.)

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question