index 辨别字符在字符串中的位置

namespace index
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string s = "abcdefghijklmn";
                int i = s.IndexOf("f"); // i是f在字符串s中的位置,这里为5,注意开始位置是0而不是1
                Console.WriteLine(i);
                string j = s.Substring(i,4);  //从第i位开始截取4个字符 (注意初始位置为0)
                Console.WriteLine(j);
                Console.ReadLine();
            }
        }
    }
}

posted @ 2015-04-02 21:11  XCml  阅读(205)  评论(0编辑  收藏  举报