473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

replacing a string that contains a " character

Hi there,

i'm trying to do a string replace on something like the following

string MyString = myinput;
myinput = myinput.Replace("src="../content/","http://www.site.com/content/")

but, the "src="../content/" line isnt working, i tried 3 quotes, 4 quotes, 5
quotes, no luck, whats the correct syntax to do this (and replace a string
that contains a quote in it)?

thanks,
Paul
May 17 '07 #1
4 3895
"Milsnips" <mi******@hotmail.comwrote in message
news:Oi**************@TK2MSFTNGP06.phx.gbl...
string MyString = myinput;
myinput =
myinput.Replace("src="../content/","http://www.site.com/content/")

but, the "src="../content/" line isnt working, i tried 3 quotes, 4 quotes,
5 quotes, no luck, whats the correct syntax to do this (and replace a
string that contains a quote in it)?
Insert a backslash before the quote:

myinput.Replace("src=\"../content/","http://www.site.com/content/")
May 17 '07 #2
Shouldn't it be .Replace
("src=\"../content/\","src='http://www.site.com/content/'") ?

"Milsnips" wrote:
Hi there,

i'm trying to do a string replace on something like the following

string MyString = myinput;
myinput = myinput.Replace("src="../content/","http://www.site.com/content/")

but, the "src="../content/" line isnt working, i tried 3 quotes, 4 quotes, 5
quotes, no luck, whats the correct syntax to do this (and replace a string
that contains a quote in it)?

thanks,
Paul
May 17 '07 #3
On May 17, 9:11 am, "Milsnips" <milsn...@hotmail.comwrote:
i'm trying to do a string replace on something like the following

string MyString = myinput;
myinput = myinput.Replace("src="../content/","http://www.site.com/content/")

but, the "src="../content/" line isnt working, i tried 3 quotes, 4 quotes, 5
quotes, no luck, whats the correct syntax to do this (and replace a string
that contains a quote in it)?
\" is the way to escape a " within a normal literal string. For a
verbatim literal, use "".

Jon

May 17 '07 #4
Aah yes i should have thought of it myself! :-))
Thanks for the replies from all.

regards,
Paul

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
On May 17, 9:11 am, "Milsnips" <milsn...@hotmail.comwrote:
>i'm trying to do a string replace on something like the following

string MyString = myinput;
myinput =
myinput.Replace("src="../content/","http://www.site.com/content/")

but, the "src="../content/" line isnt working, i tried 3 quotes, 4
quotes, 5
quotes, no luck, whats the correct syntax to do this (and replace a
string
that contains a quote in it)?

\" is the way to escape a " within a normal literal string. For a
verbatim literal, use "".

Jon

May 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: C# Learner | last post by:
What's the "standard" way of replacing a character in a string? Obviously, I can't say "myString = character;" because strings are immutable... So what would be the "standard" way of doing this?...
5
by: Jim Lawton | last post by:
Hello group, I'm not very experienced in C#, but I can't find any example of this (common) programming problem. I have a string which contains a repeated substring - lets say it's like :- ...
7
by: VMI | last post by:
If I have the string "Héllo", how can I replace char (é) with an 'e'? I cannot use the String.Replace() fuction. It has to be by replacing one char with another. Thanks.
12
by: anonymous | last post by:
Hello, I need to replace this char  with another char. However I am not able to acieve this. I tried this but it doesnt work: str = str.Replace(chr(asc(194)), "") Can somebody help ?
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
14
by: Adnan Siddiqi | last post by:
Hi Suppose I have following URLs comming from an HTML document <a href="http://mydomain1.com">Domain1</a> <a...
12
by: Ed | last post by:
Hi All, The sample code below doesn't work, but if you take out the Question Mark character, "?" in front of the value "Print" of the "action" attribute, it does work! Does anyone here know...
8
by: Choi | last post by:
Hi ! I wonder how I can replace a quote by a "\n" in a string. For example my string is rrrrrrr'ttttttt and I want to obtain : rrrrrrr ttttttt I tried the function find, but I don't know...
6
by: paulcybulski | last post by:
I am trying to pass a URL to the body of an e-mail using a shell...however the string I am trying to pass as the URL contains a "&" character which is being treated as an operator by the complier and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.