我試圖用「\」替換字符串中的所有符號爲「\\」。但它並沒有取代,我不知道爲什麼。嘗試將「a」替換爲「b」時它工作正常。代碼如下:C++ - cli如何用「\」替換「」
Private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
OpenFileDialog ^ofd = gcnew OpenFileDialog();
if (ofd->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
StreamReader ^read = gcnew StreamReader(File::OpenRead(ofd->FileName));
textBox3->Text = ofd->FileName->Replace("\"", "\\");
}
您現在正嘗試用單個反斜槓替換雙引號。文件名永遠不會包含雙引號。不清楚是什麼意思,特別是因爲它似乎沒有把Text屬性設置爲這樣一個字符串,所以考慮'Replace(「\\」,「\\\\」)' –