Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Related to question at:
- //http://groups.google.com/group/dotnetdevelopment/browse_thread/thread/54f6395f4936d6c9
- using System.Linq;
- using System.Text;
- using System.Collections.Generic;
- namespace ConsoleApplication
- {
- class PhoneParser
- {
- private const int phoneLength = 10; // Length of a phone number.
- private const int groupLength = 100; // Max length of each group of phone numbers.
- private static List<string> inputPhoneList;
- private static int phoneCount;
- static void Main(string[] args)
- {
- inputPhoneList = args[0].Split(',').ToList();
- phoneCount = inputPhoneList.Count();
- int endIdx = phoneCount > groupLength ? groupLength : phoneCount;
- List<string> phoneList = ParsePhoneList(0, endIdx);
- phoneList.ForEach((s) => { Console.WriteLine(s + "\r\n"); });
- }
- private static List<string> ParsePhoneList(int startIdx, int endIdx)
- {
- List<string> pList = new List<string>();
- StringBuilder sb = new StringBuilder(groupLength * phoneLength);
- int i = startIdx;
- while (i < endIdx)
- {
- sb.Append(inputPhoneList[i]);
- if (i < endIdx - 1)
- sb.Append(",");
- i++;
- }
- pList.Add(sb.ToString());
- if (i < phoneCount)
- {
- endIdx += groupLength;
- endIdx = phoneCount > endIdx ? endIdx : phoneCount;
- pList.AddRange(ParsePhoneList(i, endIdx));
- }
- return pList;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment