Re: [問題] 逸散字元是否能夠不用呢?

看板C_Sharp作者 (bero)時間16年前 (2009/12/20 01:20), 編輯推噓3(304)
留言7則, 3人參與, 最新討論串3/3 (看更多)
部分原始碼: private void button1_Click_1(object sender, EventArgs e) { Process.Start("C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\ powershell.exe", test.Text); } test為richtextbox 內容為 @" function aa{ "hello world" } aa read-host " hello world兩邊的"如果不改成\" 那powershell就會跑失敗... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.73.237.242

12/20 01:26, , 1F
要改成這樣 ""hello world""
12/20 01:26, 1F

12/20 01:32, , 2F
可是這樣就要動到我原本的script檔呀...希望可以完全不用改
12/20 01:32, 2F

12/20 01:34, , 3F
畢竟改\"跟改""對於後續要修改script都會造成一定程度的障礙
12/20 01:34, 3F

12/20 01:47, , 4F
請問一下你在Button_click得到的test.text是你自己輸入在
12/20 01:47, 4F

12/20 01:48, , 5F
richtextbox的值嗎?
12/20 01:48, 5F

12/20 15:42, , 6F
是的...是在visual studio裡面打的,不是編譯好執行時打的
12/20 15:42, 6F

12/20 22:09, , 7F
試試test.Text.Replace("\"", "\\\"")
12/20 22:09, 7F
文章代碼(AID): #1BBGjVtd (C_Sharp)
文章代碼(AID): #1BBGjVtd (C_Sharp)