I am adding mutliple values to single string , all the values should be like in this format '',''
but I am getting "'',''"
instead.
How can I remove these double qoutes? Here's the code I'm using:
string one = "\'"+ names[0, 0] +"\'"+","+"\'" + names[1, 0]+"\'";
string[] splitted = one.Split('\'');
string ones = "'" + splitted[1] + "'" +","+ "'" + splitted[3] + "'";
I am adding mutliple values to single string , all the values should be like in this format '',''
but I am getting "'',''"
instead.
How can I remove these double qoutes? Here's the code I'm using:
string one = "\'"+ names[0, 0] +"\'"+","+"\'" + names[1, 0]+"\'";
string[] splitted = one.Split('\'');
string ones = "'" + splitted[1] + "'" +","+ "'" + splitted[3] + "'";
Share
Improve this question
edited Aug 24, 2012 at 10:17
Rup
34.4k9 gold badges86 silver badges118 bronze badges
asked Aug 24, 2012 at 10:15
user1619151user1619151
591 gold badge2 silver badges6 bronze badges
8
|
Show 3 more comments
4 Answers
Reset to default 8You don't have to escape single quote like "\'"
instead you can simply use "'"
, so you code should be:
string one = "'" + names[0, 0] + "'" + "," + "'" + names[1, 0] + "'";
string[] splitted = one.Split('\'');
string ones = "'" + splitted[1] + "'" + "," + "'" + splitted[3] + "'";
Not sure I fully understand, but there are two ways.
Output: ".","."
var s1 = @"""."","".""";
var s2 = "\".\",\".\"";
The best way to encapsualte escape sequences and special characters within a string is the use of webatim character.
e.g.
String escSeq = "C:\\MyDocuments\\Movie";
can also be stored as:
string escSeq = @"C:\MyDocumens\Movie";
The @ character you must put before the string starts and outside the "" characters.
I just worked with your code..it works just fine..
Debugger will show: "'val1','val2'"
Actual Value : 'val1','val2'
From the debugger point you will see "'val1','val2'"
but actually it happens for every string
values. but actually when you prints the value in a page you will see the actual value as 'val1','val2'
EDIT:
For sending those values to javascript what you can do is just set those values in Hidden fields
and then fetch those value from that using document.getElementById('hidden_field')
.
string.Format
for building the strings? It could make your code a lot easier to read. – Richard Ev Commented Aug 24, 2012 at 10:17"
are actually part of your string, and not just displayed in the debugger? – Rawling Commented Aug 24, 2012 at 10:17"
is not exist after the split ? – Aristos Commented Aug 24, 2012 at 10:21