有一段字符串 比如  我,我们,我爱周星星,周星星,,,爱星星,
想找到“我爱周星星”在字符串中的位置,请问怎么写

解决方案 »

  1.   

    用不着正则吧
    String str = "我,我们,我爱周星星,周星星,,,爱星星,";
    int index = str.IndexOf("我爱周星星");//index=5;
      

  2.   

    int c = Regex.Match("我,我们,我爱周星星,周星星,,,爱星星, ", "我爱周星星", RegexOptions.IgnoreCase).Index;或者直接int c = "我,我们,我爱周星星,周星星,,,爱星星, ", "我爱周星星".IndexOf("我爱周星星");
      

  3.   

    哎贴错了第二个
    int c = "我,我们,我爱周星星,周星星,,,爱星星, ".IndexOf("我爱周星星");
      

  4.   

    int c = "我,我们,我爱周星星,周星星,,,爱星星, ".IndexOf("我爱周星星");
    c=-1就是没有,其它的就是你要的结果!