why does character such as “” error in c# [duplicate]
This question already has an answer here:
How do I write the escape char '' to code
6 answers
I have a textbox that has a value depends on the Path of the file after dragging the folder. the return value of dragged folder is "C:Program Files"
.
and I want to add the char ""
on the textbox, but if I add that character, there is an error such as red line below my code, the example of a red line is when you misspelled a word in a document.
code:
txtResult.Text + "" + textFile + ".txt"
Question:
what is the main reason that this string value does have an error?
c#
marked as duplicate by mjwills, Tetsuya Yamamoto, D-Shih, Community♦ Nov 12 '18 at 3:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How do I write the escape char '' to code
6 answers
I have a textbox that has a value depends on the Path of the file after dragging the folder. the return value of dragged folder is "C:Program Files"
.
and I want to add the char ""
on the textbox, but if I add that character, there is an error such as red line below my code, the example of a red line is when you misspelled a word in a document.
code:
txtResult.Text + "" + textFile + ".txt"
Question:
what is the main reason that this string value does have an error?
c#
marked as duplicate by mjwills, Tetsuya Yamamoto, D-Shih, Community♦ Nov 12 '18 at 3:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How do I write the escape char '' to code
6 answers
I have a textbox that has a value depends on the Path of the file after dragging the folder. the return value of dragged folder is "C:Program Files"
.
and I want to add the char ""
on the textbox, but if I add that character, there is an error such as red line below my code, the example of a red line is when you misspelled a word in a document.
code:
txtResult.Text + "" + textFile + ".txt"
Question:
what is the main reason that this string value does have an error?
c#
This question already has an answer here:
How do I write the escape char '' to code
6 answers
I have a textbox that has a value depends on the Path of the file after dragging the folder. the return value of dragged folder is "C:Program Files"
.
and I want to add the char ""
on the textbox, but if I add that character, there is an error such as red line below my code, the example of a red line is when you misspelled a word in a document.
code:
txtResult.Text + "" + textFile + ".txt"
Question:
what is the main reason that this string value does have an error?
This question already has an answer here:
How do I write the escape char '' to code
6 answers
c#
c#
asked Nov 12 '18 at 2:58
Alexis VillarAlexis Villar
18211
18211
marked as duplicate by mjwills, Tetsuya Yamamoto, D-Shih, Community♦ Nov 12 '18 at 3:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by mjwills, Tetsuya Yamamoto, D-Shih, Community♦ Nov 12 '18 at 3:13
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
When inside a string the backslash character ''
, it is interpreted as an escape character.
In your case it's escaping
the double quote
, which is nesseccary when you want a double quote character inside a quoted string. However since you want the literal backslash, you should escape the backslash, which Means:
Use "\"
.
Now it will produce a single backslash.
Edit:
Another option is to use an @-quoted string
, like this:
@""
Now you don't have to escape the character.
You may also use verbatim string:var path = @"C:Program Files";
– vasily.sib
Nov 12 '18 at 3:07
thank sir :) got it :)
– Alexis Villar
Nov 12 '18 at 3:13
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When inside a string the backslash character ''
, it is interpreted as an escape character.
In your case it's escaping
the double quote
, which is nesseccary when you want a double quote character inside a quoted string. However since you want the literal backslash, you should escape the backslash, which Means:
Use "\"
.
Now it will produce a single backslash.
Edit:
Another option is to use an @-quoted string
, like this:
@""
Now you don't have to escape the character.
You may also use verbatim string:var path = @"C:Program Files";
– vasily.sib
Nov 12 '18 at 3:07
thank sir :) got it :)
– Alexis Villar
Nov 12 '18 at 3:13
add a comment |
When inside a string the backslash character ''
, it is interpreted as an escape character.
In your case it's escaping
the double quote
, which is nesseccary when you want a double quote character inside a quoted string. However since you want the literal backslash, you should escape the backslash, which Means:
Use "\"
.
Now it will produce a single backslash.
Edit:
Another option is to use an @-quoted string
, like this:
@""
Now you don't have to escape the character.
You may also use verbatim string:var path = @"C:Program Files";
– vasily.sib
Nov 12 '18 at 3:07
thank sir :) got it :)
– Alexis Villar
Nov 12 '18 at 3:13
add a comment |
When inside a string the backslash character ''
, it is interpreted as an escape character.
In your case it's escaping
the double quote
, which is nesseccary when you want a double quote character inside a quoted string. However since you want the literal backslash, you should escape the backslash, which Means:
Use "\"
.
Now it will produce a single backslash.
Edit:
Another option is to use an @-quoted string
, like this:
@""
Now you don't have to escape the character.
When inside a string the backslash character ''
, it is interpreted as an escape character.
In your case it's escaping
the double quote
, which is nesseccary when you want a double quote character inside a quoted string. However since you want the literal backslash, you should escape the backslash, which Means:
Use "\"
.
Now it will produce a single backslash.
Edit:
Another option is to use an @-quoted string
, like this:
@""
Now you don't have to escape the character.
edited Nov 12 '18 at 3:09
answered Nov 12 '18 at 3:05
Poul BakPoul Bak
5,48831233
5,48831233
You may also use verbatim string:var path = @"C:Program Files";
– vasily.sib
Nov 12 '18 at 3:07
thank sir :) got it :)
– Alexis Villar
Nov 12 '18 at 3:13
add a comment |
You may also use verbatim string:var path = @"C:Program Files";
– vasily.sib
Nov 12 '18 at 3:07
thank sir :) got it :)
– Alexis Villar
Nov 12 '18 at 3:13
You may also use verbatim string:
var path = @"C:Program Files";
– vasily.sib
Nov 12 '18 at 3:07
You may also use verbatim string:
var path = @"C:Program Files";
– vasily.sib
Nov 12 '18 at 3:07
thank sir :) got it :)
– Alexis Villar
Nov 12 '18 at 3:13
thank sir :) got it :)
– Alexis Villar
Nov 12 '18 at 3:13
add a comment |