Mahmoud Elmahdi
Mahmoud Elmahdi

Reputation: 1

C# double " mark in textstring

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

Upvotes: 0

Views: 59

Answers (2)

Jonathan
Jonathan

Reputation: 5018

You can use a 'verbatim identifier' (@) and escape quotes with double quotes.

Note that you can also combine the 'string interpolation identifier' ($) so that you're not building up the string with pluses. See:

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/verbatim

and

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated

Then you could write your code something like:

var myString = @$"QUESTID = LuaGetQuestID(""{textBox1.Text}"")";

Upvotes: 2

Mahmoud Elmahdi
Mahmoud Elmahdi

Reputation: 1

thanks, guys it works with this code

File.Write("  QUESTID = LuaGetQuestID(" + '"' + textBox1.Text + '"' + ")\r\n");

Upvotes: 0

Related Questions