string s = "2005-09-A11-3城市规划图"; MessageBox.Show(s.Substring(s.IndexOf("城")));
string ptn = @"^[0-9-A-Z]+(?<text>.*)$"; string s = "2005-09-A11-3城市规划图"; Regex reg = new Regex(ptn, RegexOptions.IgnoreCase); Match m = reg.Match(s); Console.WriteLine(m.Groups["text"].Value);
using System; using System.Text.RegularExpressions;class Test { static void Main() { string pattern = @"^[\x00-\xff]*(?<a>.*)$"; string s0 = "2005-09-A11-3城市规划图"; string s1 = Regex.Match(s0, pattern).Groups["a"].Value; Console.WriteLine(s1); } }/* 程序输出: 城市规划图 */
那就只能正则表达式了,正则表达式也必须前面有一定规律才行.如果怕麻烦,生成字符串的时候加个固定的分隔符号也就可以用我那个方法了! 比如 string s = "2005-09-A11-3|城市规划图"; MessageBox.Show(s.Substring(s.IndexOf("|") + 1));
MessageBox.Show(s.Substring(s.IndexOf("城")));
string s = "2005-09-A11-3城市规划图";
Regex reg = new Regex(ptn, RegexOptions.IgnoreCase);
Match m = reg.Match(s);
Console.WriteLine(m.Groups["text"].Value);
using System.Text.RegularExpressions;class Test
{
static void Main()
{
string pattern = @"^[\x00-\xff]*(?<a>.*)$";
string s0 = "2005-09-A11-3城市规划图";
string s1 = Regex.Match(s0, pattern).Groups["a"].Value;
Console.WriteLine(s1);
}
}/* 程序输出:
城市规划图
*/
比如
string s = "2005-09-A11-3|城市规划图";
MessageBox.Show(s.Substring(s.IndexOf("|") + 1));