Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best way to parse fixed length text file
Message
From
29/04/2009 10:19:09
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01396650
Message ID:
01396960
Views:
75
>I'm processing line by line - I tried that pattern change and it didn't work

It does over here - anyone missed something ?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;


namespace GregoryAdam.Test
{
	public static class testegex
	{
		public static void Main()
		{

			string s = @"BX00027025  AD               ME                CW                   NO'S ALLOCATED TO KEW TRUNKS   29/03/1994";
			string pattern = "^(BX.{10})(.{17})(.{18})(.{21})(.{31})(.{10})$";

			MatchCollection matches = Regex.Matches(s, pattern);

			if (matches.Count != 1)
			{
				Console.WriteLine("problem");
			}
			else
			{
				Match match = matches[0];

				GroupCollection groups = match.Groups;

				// groups[0] is the whole line
				// start at 1
				for (int i = 1; i < groups.Count; i++)
				{
					Console.WriteLine("{0}:{1}", i, groups[i].Value);
				}
				Console.ReadLine();
			}

		}
	}
}
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform