C#判断字符串中是否具有非法字符
string a = textBox1.Text; if (!string.IsNullOrEmpty(a))//判断字符串是否为空 { if (a.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)//判断路径中是否有非法字符 { MessageBox.Show("路径中具有非法字符"); } }
string a = textBox1.Text; if (!string.IsNullOrEmpty(a))//判断字符串是否为空 { if (a.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)//判断路径中是否有非法字符 { MessageBox.Show("路径中具有非法字符"); } }
