Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 9th, 2007, 12:58 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Replce Problem

How to replace "\" with "\\"
i am using str.replace("\","\\") but its not working


Reply With Quote
  #2 (permalink)  
Old January 9th, 2007, 01:10 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

The character '\' is used as an escape character.
So when you include it in a string the next char is the one that is considered what you are after.
So str.replace("\","\\") means if you find 'nothing/empty string' replace it with one '\'.
You need something like the following
str.replace("\\","\\\\")
or
str.replace(@"\",@"\\")
I think the second is the better approach

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
Reply With Quote
  #3 (permalink)  
Old January 9th, 2007, 02:33 AM
Authorized User
 
Join Date: Nov 2006
Location: New Delhi, Delhi, India.
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

your may use.
str=str.Replace("\","\\");
because str.Replace only makes virtual changes.
not stored to your str variable.Ok
I Think This one help you.

Thanks and Regards
Kumar Ashish
9350789189
Reply With Quote
  #4 (permalink)  
Old January 9th, 2007, 03:39 AM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by rodmcleay
 The character '\' is used as an escape character.
So when you include it in a string the next char is the one that is considered what you are after.
So str.replace("\","\\") means if you find 'nothing/empty string' replace it with one '\'.
You need something like the following
str.replace("\\","\\\\")
or
str.replace(@"\",@"\\")
I think the second is the better approach

======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================

thank you
now my problem get solved by your solution
tnaks a lot


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off




All times are GMT -4. The time now is 07:58 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.