Reputation: 41
I want to have a program that will be able to write to the file:
addr_new = serverInfo.REGION_DICT[0][serverNum]["channel"][serverChannel]["ip"]
, but must ignore the characters "" in the text
My restult: Visual studio does not ignores characters "" in string and wants strings like IP etc.. thx for help
Sry for my english
There is my Program:
string path = System.IO.Directory.GetCurrentDirectory()+ "logininfo.py";
string[] lines = {
"import serverInfo"
, "serverNum=1"
, "serverChannel=1"
, "addr_new = serverInfo.REGION_DICT[0][serverNum]["channel"][serverChannel]["ip"]"};
System.IO.StreamWriter file = new System.IO.StreamWriter(path);
file.WriteLine(lines);
file.Close();
I almost forgot I want more lines, this program is trimmed
Upvotes: 3
Views: 24588
Reputation: 25201
You can escape those characters with a slash:
string[] lines = {
" import serverInfo" ,
"serverNum=1" ,
"serverChannel=1" ,
"addr_new = serverInfo.REGION_DICT[0][serverNum][\"channel\"][serverChannel][\"ip\"] "};
or use a @-quoted string and use ""
instead of "
like so:
string[] lines = {
" import serverInfo" ,
"serverNum=1" ,
"serverChannel=1" ,
@"addr_new = serverInfo.REGION_DICT[0][serverNum][""channel""][serverChannel][""ip""] "};
Upvotes: 4
Reputation: 26376
Escape the special characters
"addr_new = serverInfo.REGION_DICT[0][serverNum][\"channel\"][serverChannel][\"ip\"]"
Upvotes: 0
Reputation: 103338
You need to concatenate the strings:
"addr_new = serverInfo.REGION_DICT[0][serverNum][" + channel + "][serverChannel][" + ip + "]"};
Or if you wish for "channel" to be used as a string value, use single quotes:
"addr_new = serverInfo.REGION_DICT[0][serverNum]['channel'][serverChannel]['ip']"};
Upvotes: 2