static int LinesCount(string str)

来源:互联网 发布:剑网三脸型数据 编辑:程序博客网 时间:2024/04/27 20:32
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication3
{
    class Program
    {
        static int LinesCount(string str)
        {
            int i = 0;
            int counter=0;
            for (i = 0; i < str.Length; i++)
            {
                if (str[i] == '\n')
                {
                    ++counter;
                }
            }


            return counter;
        }


        static List<int> PositionList(string str,string[] args)//public private
        {
            List<int> result = new List<int>();
            foreach (string arg in args)
            {
                int posStart=0;
                int index = 0;
                while ((index = str.IndexOf(arg, posStart)) != -1)
                {
                    result.Add(index);
                    posStart = index + 1;
                    if (posStart >= str.Length - 1)
                    {
                        break;
                    }
                }
            }
            //sort asc
            result.Sort();
            return result;
        }


        static string GetLine(string str,int pos)
        {
            int posA = pos;
            int posB = pos;
            while (str[posA]!='\n')
            {
                posA -= 1;
                if (posA == 0)
                    break;
            }
            posA = (str[posA] == '\n') ? (posA + 1) : posA;


            while (str[posB] != '\n')
            {
                posB += 1;
                if (posB == str.Length)
                {
                    break;
                }
            }
            posB = (str[posB] == '\n') ? posB : (posB - 1);


            return str.Substring(posA, posB - posA);


        }


        static void Main(string[] args)
        {
        }
    }
}
0 0
原创粉丝点击