?
Solved

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

Posted on 2003-03-14
6
Medium Priority
?
325 Views
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??!!
0
Comment
Question by:FlorenceYee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:smegghead
ID: 8143057
put a @ infront of the string

i.e.

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

Expert Comment

by:AvonWyss
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, @"\\|/", "");
0
 

Author Comment

by:FlorenceYee
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
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;
}
0
 
LVL 14

Expert Comment

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

Expert Comment

by:AvonWyss
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.)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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