Hi,
I have a string:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
how can I use the c.Replace(???, ???) method to have this string:
"'abc' "cde", 'mno' "xyz","
that is, all the backslashes are removed.
Thanks,
Etu 14 3244
In the line of code you wrote:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
there are no backslashes in the string. The backslashes you see are
only a typographical convention that tells the compiler that the
double-quote that follows each backslash is not the double-quote that
ends the string, but that it should instead place a double-quote
character in the string.
The string stored internally after compilation looks like this:
'abc' "cde", 'mno' "xyz",
What are you trying to do in your program and what problems are you
encountering, since backslashes in the string don't appear to be what's
wrong?
string c = "'abc' \"cde\", 'mno' \"xyz\",";
string clearString = c.Replace('\\', ' '); // You must type backslash twice
That's All
Hopes This Helps
"Etu" <et*****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... Hi,
I have a string:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
how can I use the c.Replace(???, ???) method to have this string:
"'abc' "cde", 'mno' "xyz"," that is, all the backslashes are removed.
Thanks,
Etu
Thanks Bruce!
The problem I have is actually my program first reads some strings
(with \t, \" and so on) from an XML file and writes these strings to an
Excel file. After the Excel file is saved, \t becomes a space and \"
becomes ". Then when my program later reads the strings from the Excel
file, it doesn't think the strings are the same as those in the XML
file.
That is why I was trying to modify the strings from the XML file by
getting rid of the backslashes - try to do the same thing that Excel
does, but could not find a way to do so.
Thanks
Bruce Wood wrote: In the line of code you wrote:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
there are no backslashes in the string. The backslashes you see are only a typographical convention that tells the compiler that the double-quote that follows each backslash is not the double-quote that ends the string, but that it should instead place a double-quote character in the string.
The string stored internally after compilation looks like this:
'abc' "cde", 'mno' "xyz",
What are you trying to do in your program and what problems are you encountering, since backslashes in the string don't appear to be
what's wrong?
Thanks SerhaD. However, I tried your code but could not get what I
want.
Thanks
SerhaD Inanli wrote: string c = "'abc' \"cde\", 'mno' \"xyz\","; string clearString = c.Replace('\\', ' '); // You must type backslash
twice That's All
Hopes This Helps
"Etu" <et*****@yahoo.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... Hi,
I have a string:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
how can I use the c.Replace(???, ???) method to have this string:
"'abc' "cde", 'mno' "xyz"," that is, all the backslashes are removed.
Thanks,
Etu
"SerhaD Inanli" <se**********@hotmail.com> wrote in message
news:eV**************@TK2MSFTNGP14.phx.gbl... string c = "'abc' \"cde\", 'mno' \"xyz\","; string clearString = c.Replace('\\', ' '); // You must type backslash
twice
Yes but will this make any difference... to the out put... c and clearString
both are same as you out them...??? That's All
Hopes This Helps
"Etu" <et*****@yahoo.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... Hi,
I have a string:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
how can I use the c.Replace(???, ???) method to have this string:
"'abc' "cde", 'mno' "xyz"," that is, all the backslashes are removed.
Thanks,
Etu
Thanks Bruce!
The problem I have is actually my program first reads some strings
(with \t, \" and so on) from an XML file and writes these strings to an
Excel file. After the Excel file is saved, \t becomes a space and \"
becomes ". Then when my program later reads the strings from the Excel
file, it doesn't think the strings are the same as those in the XML
file.
That is why I was trying to modify the strings from the XML file by
getting rid of the backslashes - try to do the same thing that Excel
does, but could not find a way to do so.
Thanks
Bruce Wood wrote: In the line of code you wrote:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
there are no backslashes in the string. The backslashes you see are only a typographical convention that tells the compiler that the double-quote that follows each backslash is not the double-quote that ends the string, but that it should instead place a double-quote character in the string.
The string stored internally after compilation looks like this:
'abc' "cde", 'mno' "xyz",
What are you trying to do in your program and what problems are you encountering, since backslashes in the string don't appear to be
what's wrong?
Thanks SerhaD. However, I tried your code but could not get what I
want.
Thanks
SerhaD Inanli wrote: string c = "'abc' \"cde\", 'mno' \"xyz\","; string clearString = c.Replace('\\', ' '); // You must type backslash
twice That's All
Hopes This Helps
"Etu" <et*****@yahoo.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... Hi,
I have a string:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
how can I use the c.Replace(???, ???) method to have this string:
"'abc' "cde", 'mno' "xyz"," that is, all the backslashes are removed.
Thanks,
Etu
"SerhaD Inanli" <se**********@hotmail.com> wrote in message
news:eV**************@TK2MSFTNGP14.phx.gbl... string c = "'abc' \"cde\", 'mno' \"xyz\","; string clearString = c.Replace('\\', ' '); // You must type backslash
twice
Yes but will this make any difference... to the out put... c and clearString
both are same as you out them...??? That's All
Hopes This Helps
"Etu" <et*****@yahoo.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... Hi,
I have a string:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
how can I use the c.Replace(???, ???) method to have this string:
"'abc' "cde", 'mno' "xyz"," that is, all the backslashes are removed.
Thanks,
Etu
private void RegEx_Click(object sender, System.EventArgs e)
{
string c = "'abc' \"cde\", 'mno' \"xyz\",";
try
{
textBox1.Text = c.Replace('\\', ' '); // Second parameter is a blank char
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
and Result is = 'abc' "cde", 'mno' "xyz",
I Tried several times , do u get different output or Error ?
"Etu" <et*****@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... Thanks SerhaD. However, I tried your code but could not get what I want.
Thanks
SerhaD Inanli wrote: string c = "'abc' \"cde\", 'mno' \"xyz\","; string clearString = c.Replace('\\', ' '); // You must type backslash twice That's All
Hopes This Helps
"Etu" <et*****@yahoo.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... Hi,
I have a string:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
how can I use the c.Replace(???, ???) method to have this string:
"'abc' "cde", 'mno' "xyz"," that is, all the backslashes are removed.
Thanks,
Etu
private void RegEx_Click(object sender, System.EventArgs e)
{
string c = "'abc' \"cde\", 'mno' \"xyz\",";
try
{
textBox1.Text = c.Replace('\\', ' '); // Second parameter is a blank char
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
and Result is = 'abc' "cde", 'mno' "xyz",
I Tried several times , do u get different output or Error ?
"Etu" <et*****@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... Thanks SerhaD. However, I tried your code but could not get what I want.
Thanks
SerhaD Inanli wrote: string c = "'abc' \"cde\", 'mno' \"xyz\","; string clearString = c.Replace('\\', ' '); // You must type backslash twice That's All
Hopes This Helps
"Etu" <et*****@yahoo.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... Hi,
I have a string:
string c = "'abc' \"cde\", 'mno' \"xyz\",";
how can I use the c.Replace(???, ???) method to have this string:
"'abc' "cde", 'mno' "xyz"," that is, all the backslashes are removed.
Thanks,
Etu
Etu,
Why do you think that your C# program doesn't think the strings are the same
as those in the XML file?
If you are watching this in the debugger then you will see tabs replaced
with \t, quotes replaced with \" but this is just a display convention. The
debugger wants to display all strings like C# constants, and a C# constant
can't contain a quote, so it'll be changed to \" to be syntactially correct.
And any escapable characters will be transformed to escape sequences so that
you can see they are there.
If you are reading the XML files and they don't have the backslashes then C#
won't magically add them back in.
In a similar vein, why do you think that Excel changes tabs to spaces? It
might be doing so, particularly if it doesn't understand \t but realizes
it's some kind of escape sequence and changes it to a space; or, it may know
it's a tab but disallows or transforms them in that context. But if you are
going by what your eye sees to draw this conclusion then you may be drawing
the wrong conclusion. It may well *be* a tab.
--Bob
"Etu" <et*****@yahoo.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com... The problem I have is actually my program first reads some strings (with \t, \" and so on) from an XML file and writes these strings to an Excel file. After the Excel file is saved, \t becomes a space and \" becomes ". Then when my program later reads the strings from the Excel file, it doesn't think the strings are the same as those in the XML file.
Ahhh... so the string you have was read from a file, not compiled into
your program. That makes all of the difference in the world. If the
string is read from a file, it really does have backslashes in it. If
it was compiled into your program, it doesn't.
Evidently, Excel processes the string during input and converts the
escape sequences (\", \t, \n, and the like) into their corresponding
characters (", tab, and newline, respectively).
I don't know of any built-in .NET method that will this processing for
you (take a string containing escape sequences and translate them to
their character equivalents). To do a 100% job would be a huge
challenge, but you can do the most common sequences (and perhaps all of
the ones you need) like this:
string cleanString;
cleanString = stringFromXmlFile.Replace("\\\"", "\"").Replace("\\t",
"\t").Replace("\\n", "\n");
You can add as many "replace" calls as you need to do the job.
The first Replace call is different because it involves the
double-quote, which is also the string delimeter in C#, so it needs
some special help. This replace call says, "Replace every occurrence of
a backslash (\\, because a \ by itself is an escape, so two \\
represent a single \ to the compiler) followed by a double-quote (\"
because you can't just say " or that would end the string) to a
double-quote."
The subsequent Replace calls are simpler. They say, "Replace every
occurrence of a backslash (\\ again) followed by (for example) an en by
(for example) the character \n." The compiler translates \n into the
newline character, so the Replace ends up replacing every two-character
sequence \n by the new line character.
You can do the same for tab (\t), return (\r), and a bunch of other
characters. See here for the common ones: http://msdn.microsoft.com/library/de...ec_2_4_4_4.asp
(watch for line wrapping on the URL).
Mind you, this won't trap all possible values: you can also use the \
escape character in C# followed by a hexadecimal or Unicode escape
sequence, which could indicate any character in the massive Unicode
character space. This Replace trick won't work in that case. I'll leave
it to someone smarter than I am to come up with a solution for that
one.
However, if you don't have any backslashes followed by numeric
sequences in your XML code, then you're probably fine with the trick I
outlined above.
I appreciate your help, Bob. I jumped to the wrong conclusion but
later found that the reason my program doesn't "think" the two strings
are the same because the first apostrophe was not saved to the Excel
file!
Etu This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Craig Keightley |
last post by:
Can these lines of sql statements be consolidated into one sql statement
(possibly using reg exps??)
BEGIN CODE
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Update...
|
by: Barnes |
last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form?
Here is the scenario:
I have a form that cannot accept apostrophes. I want to use the replace() so...
|
by: Danny |
last post by:
I need an asp command to strip out from a string all extra punctuation such
as apostrophe, comma, period, spaces dashes, etc etc and just leave the
letters.
Can anybody give me some ideas?
...
|
by: Peter Row |
last post by:
Hi,
I know this has been asked before, but reading the threads it is still not
entirely clear.
Deciding which .Replace( ) to use when.
Typically if I create a string in a loop I always use a...
|
by: Cor |
last post by:
Hi Newsgroup,
I have given an answer in this newsgroup about a "Replace".
There came an answer on that I did not understand, so I have done some
tests.
I got the idea that someone said,...
|
by: Goran Djuranovic |
last post by:
Hi all,
I ran into a problem where my XMLTextReader fails on .Read() when I have "<" character in one of the attribute's values. What I am trying to do is replace illegal characters ("<", "&" ,...
|
by: TOXiC |
last post by:
Hi everyone,
First I say that I serched and tryed everything but I cannot figure
out how I can do it.
I want to open a a file (not necessary a txt) and find and replace a
string.
I can do it...
|
by: JackpipE |
last post by:
Here is my replace query and I need to run this on every column in my
table. Right now I manually enter the column name (_LANGUAGES_SPOKEN)
but this is time consuming and would like to automate...
|
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...
|
by: =?Utf-8?B?TWlrZSAiWU9fQkVFIiBC?= |
last post by:
I have a text file that contains about 8 to 10 text sequences that I need to
replace.
I want to search and replace all 8 to 10 text sequence anytime I run this
script
Here is what I have so...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
| |