I've been trying different methods for replacing escaped strings. None
work. I even have a custom Replace() method but still can't get what I
need. Some of the characters I need to replace are:
\r\n with nothing
\" with only single quote.
myString = myString.Replac e(@"\"", @""");
Replace(myStrin g, @"\"", @""");
gives this error:
No overload for method 'Replace' takes '2' arguments
or
Replace(myStrin g, @"\\""", @""""));
which doesn't work
//Replace function that I'm using
public static String Replace(String strText,String strFind,String
strReplace)
{
int iPos=strText.In dexOf(strFind);
String strReturn="";
while(iPos!=-1)
{
strReturn+=strT ext.Substring(0 ,iPos) + strReplace;
strText=strText .Substring(iPos +strFind.Length );
iPos=strText.In dexOf(strFind);
}
if(strText.Leng th>0)
strReturn+=strT ext;
return strReturn;
}
Any suggestions?
Thanks,
Brett 6 5397
Brett <no@spam.com> wrote: I've been trying different methods for replacing escaped strings. None work. I even have a custom Replace() method but still can't get what I need. Some of the characters I need to replace are: \r\n with nothing \" with only single quote.
myString = myString.Replac e(@"\"", @""");
You don't want those to be verbatim string literals, due to the quote
myString = myString.Replac e ("\\\"", "\"");
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... Brett <no@spam.com> wrote: I've been trying different methods for replacing escaped strings. None work. I even have a custom Replace() method but still can't get what I need. Some of the characters I need to replace are: \r\n with nothing \" with only single quote.
myString = myString.Replac e(@"\"", @""");
You don't want those to be verbatim string literals, due to the quote
myString = myString.Replac e ("\\\"", "\"");
That isn't working. The before and after strings are the same. Here's an
example of the original string:
<A href=\"http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm\">
I want to eliminate the \ in the above.
Thanks,
Brett
"Brett" <no@spam.com> wrote in message
news:uB******** ******@TK2MSFTN GP14.phx.gbl... "Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message news:MP******** *************** *@msnews.micros oft.com... Brett <no@spam.com> wrote: I've been trying different methods for replacing escaped strings. None work. I even have a custom Replace() method but still can't get what I need. Some of the characters I need to replace are: \r\n with nothing \" with only single quote.
myString = myString.Replac e(@"\"", @""");
You don't want those to be verbatim string literals, due to the quote
myString = myString.Replac e ("\\\"", "\"");
That isn't working. The before and after strings are the same. Here's an example of the original string:
<A href=\"http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm\">
I want to eliminate the \ in the above.
Thanks, Brett
A little additional info.
string mytest = "<A
href=\"http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm\">" ;
string _mytest = mytest.Replace( "\\\"", "--");
When I walk through this code to the closing method brace, here's what I get
in the watch window:
_mytest error: identifier '_mytest' out of scope
mytest.Replace( "\\\"", "--") error: 'mytest.Replace ' does not exist
mytest "<A href=\"http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm\">"
string
No errors. Any idea why that is going on?
"Brett" <no@spam.com> wrote in message
news:uB******** ******@TK2MSFTN GP14.phx.gbl... <A href=\"http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm\">
I want to eliminate the \ in the above.
assuming you mean something like this
string str = "<A
href=\"http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm\">" ;
There IS NO '\' in the string
The \" that you see in the string declaration is stored as an " in the
actual string
if you do
Console.WriteLi ne("{0}", str);
you get
<A href="http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm">
Hopefully this is what you mean
Bill
"Bill Butler" <Bi@DigitalArts .c0m> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. .. "Brett" <no@spam.com> wrote in message news:uB******** ******@TK2MSFTN GP14.phx.gbl...
<A href=\"http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm\">
I want to eliminate the \ in the above.
assuming you mean something like this string str = "<A href=\"http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm\">" ;
There IS NO '\' in the string
The \" that you see in the string declaration is stored as an " in the actual string if you do Console.WriteLi ne("{0}", str); you get <A href="http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm">
Hopefully this is what you mean
Bill
You're so right. Thanks for clearing it up.
Brett
Brett <no@spam.com> wrote: A little additional info.
string mytest = "<A href=\"http://dslstart.verizo n.net/vzn.dsl/dog/advance.htm\">" ; string _mytest = mytest.Replace( "\\\"", "--");
There's no backslash in the string above. There is in the source code,
but not in the actual string.
When I walk through this code to the closing method brace, here's what I get in the watch window:
That's not showing you the actual string - it's escaping it for you,
somewhat unhelpfullly.
See http://www.pobox.com/~skeet/csharp/s....html#debugger
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rob |
last post by:
Hi all,
I have the following info in my database
ID | Name
================
1 | Author\'s
As you can see, the name value has been escaped. Now, the question is,
how do you match on a value that has escaped charaters? I've tried the
|
by: Lukasz Indyk |
last post by:
hello;)
i have a piece of html code, and want to replace every image on my page
with this code. now i do it by replacing IMG node with SPAN node, and
then setting innerHTML property of SPAN node with my html code:
var nodeToReplaceWith = document.createElement("<SPAN>");
nodeToReplaceWith.innerHTML = HTMLCodeToReplaceWith;...
|
by: Micha³ Gancarski |
last post by:
Hello!
How do one unescape strings prepared with pg_escape_string() ?
stripslashes() will not work because both these functions are not
completely compatible.
Thank you all in advance
--
Micha³ Gancarski
|
by: jgabbai |
last post by:
Hi,
What is the best way to white list a set of allowable characters using
regex or replace? I understand it is safer to whitelist than to
blacklist, but am not sure how to go about it.
Many thanks!
|
by: metaperl |
last post by:
I downloaded a file which has a space in the filename. I want to run a
shell unzip on it, but it fails in my current code:
syscmd = "cd %s ; unzip %s" % (self.storage.input,
file.basename())
os.system(syscmd)
because no escaping was done.
Is there a more principled way to construct a shell command and execute
| |
by: V S Rawat |
last post by:
I was trying to use back-to-back replace functions to convert a url:
str1 =
str.replace("%2F","/").replace("%3F","?").replace("%3D","=").replace("%2
6","&");
It didn't replace all 4 types of strings.
Then, I googled and found this suggestion of some JavaScript Tutorials,
so I used replace with a regex with a global switch:
|
by: dkirkdrei |
last post by:
I am having a bit of trouble trying to double up on slashes in a file
path. What I am trying to do is very similar to the code below:
<?
$var = "\\wusais\Intranets\Intranets\fpdb\pdf\weinig\00505882.pdf";
$new = preg_replace("\\", "\\\", "$var");
?>
Code above produces the following error:
|
by: magix |
last post by:
Hi,
I have
char* str1 = "d:\temp\data\test.txt"
I want to replace all the "\" to be "\\", so that
the string will have "d:\\temp\\data\\test.txt"
Can you help ?
|
by: stefcollect |
last post by:
Hi all,
I am pretty new to PHP and am stuck on - what I think - is a generic
string handling problem.
I need to read and manipulate some HTML files and have a problem in
getting some substrings found even when - it is clear - strings are
there. (see a HTML chunk I need to edit at the end of this email).
In particular, the following...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |