我想写一些c#代码,我在字符串中找到一个特定的单词,并从字符串中删除它而不删除整个字符串.
我尝试了这个但是它不起作用:
if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// Read the files
for (int i = 0; i < openFile.FileNames.Count(); i++ )
{
if (openFile.FileNames[i].Contains("Unknown Album"))
{
openFile.FileNames[i] =
openFile.FileNames[i].Replace("Unknown Album", string.Empty);
}
}
}
Run Code Online (Sandbox Code Playgroud)
该类的.FileNames属性OpenFileDialog是readonly.您必须将值存储在临时字符串中.
http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.filenames.aspx