+ Reply to Thread
Results 1 to 2 of 2

Thread: read numbers using regex

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    11

    read numbers using regex

    Hi , i have bunch of numbers like "1108656 1108657 1108658 1108659 1108660 1108661 1108662 1108663 1108664 1108665 1108666" inside file and identify them and add them to list

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    30
    To split Numbers in each line , you need to use a split method , then add the splited value into list
    Code:
    List<string> list = new List<string>();
    foreach(string line in File.ReadAllLines(@"file.txt"))
    {
        string[] numbers = line.Split(' ');
        foreach(string number in numbers)
        {
           foreach(Match match in Regex.Matches("1108656 1108657 1108658 1108659", "[0-9]{5,8}"))
           {
               if(match.Value like number)
               {
                   list.Add(number);
               }
           }
        }
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts