Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi guys I made an app to extract .lua file when I push the button
my problem is I need to pass this string like this
QUESTID = LuaGetQuestID("QNO_QUEST_AR")

QNO_QUEST_AR extracted from textBox1 so my code =
File.Write("  QUESTID = LuaGetQuestID("+textBox1.Text+")\r\n");

I need to add 2x " mark like this (""+textBox1.Text+"")
anyway to do that ? thanks

What I have tried:

try some failed method from my head :)
Posted
Updated 5-Aug-21 19:47pm

In C#, there are a couple of better ways to do this: you can escape the double quote character:
C#
File.Write("  QUESTID = LuaGetQuestID(\"" + textBox1.Text + "\")\r\n");
Or you can use string interpolation and escape it:
C#
File.Write($"  QUESTID = LuaGetQuestID(\"{textBox1.Text}\")\r\n");


Comment:
You can't include '\r' or '\n' in verbatim strings. The only interpreted character sequences are "double double-quote" for a double quote, and double curly braces for curly braces in verbatim interpolated strings:
C#
PointF p = new PointF(12.3F, 55.9F);
Console.WriteLine(@$"""{p.ToString()}""{\r\n}");

Will give you
"{X=12.3, Y=55.9}"{\r\n}
 
Share this answer
 
v2
Comments
PIEBALDconsult 6-Aug-21 10:37am    
Or use a verbatim string.
OriginalGriff 6-Aug-21 11:05am    
You can't include '\r' or '\n' in verbatim strings. The only interpreted character sequences are "double double-quote" for a double quote, and double curly braces for curly braces in verbatim interpolated strings:
PointF p = new PointF(12.3F, 55.9F);Console.WriteLine(@$"""{p.ToString()}""{\r\n}");

Will give you
"{X=12.3, Y=55.9}"{\r\n}
PIEBALDconsult 6-Aug-21 11:10am    
string s = @"
this
is
a
verbatim
string
" ;
OriginalGriff 6-Aug-21 11:07am    
Bloody thing ... I'll add that to the solution, so it's easier to read ...
My fault - I missed a "/" in the closing tag ... :O
thanks guys its work with this code.
File.Write("  QUESTID = LuaGetQuestID(" + '"' + textBox1.Text + '"' + ")\r\n");
 
Share this answer
 
Comments
PIEBALDconsult 6-Aug-21 10:38am    
Please don't try to answer your own question. Just add that to the question.
(And don't do it that way.)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900