Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all
I want read blocks of this text

LXKM/AD310T0901E/IRNCPK1V53411100/006 13-08-19 03:00:11
8917(7475) OMT-01/ITMTAC 2893/06189

TRAFFIC MEASUREMENT : TRUNK GROUP 13-08-17 00:15

DATA QUALITY : SECURE

TGNO : VLX22 VLX27 VLX281 V100K
OPMODE/TGRPTYP : BW BW BW BW
AVAILABILITY :
--------------------+---------+-------+-------+-------+-------+-------
CC:I 3 59 1 50
TC:I (DERL) 4 31 2 62
CCS WITH ANSWER:I 4 40 1 35
TC ANSWER:I (DERL) 3 30 2 47




LXKM/AD310T0901E/IRNCPK1V53411100/006 13-08-19 03:00:15
8917(7475) OMT-01/ITMTAC 2893/06189

TRAFFIC MEASUREMENT : TRUNK GROUP 13-08-17 00:15

DATA QUALITY : SECURE

TGNO : V7BSTD
OPMODE/TGRPTYP : BW
AVAILABILITY :
--------------------+---------+-------+-------+-------+-------+-------
CC:I 7
TC:I (DERL) 5
CCS WITH ANSWER:I 4
TC ANSWER:I (DERL) 3


this text has two blocks . How can I read and separate these blocks ?
Posted
Comments
BillWoodruff 29-Dec-13 2:12am    
First, you need to show us how you define the start and end of a "block."

As has been pointed out by others you don't indicate how the blocks are separated and until you are able to indicate the series of characters that marks the end of a block any solution offered can only be a guess.

Because it looks like the second block is separated from the first by 4 empty lines we'll assume for the sake of example that the block separator is four crlf character pairs.
C#
// Assumption: The gap between the end of one block and the next is 4 carriage
// return, line feed pairs. If it isn't you'll have to work out the appropriate
// regex pattern for the delimiter.
const string DELIMITER = @"[\r\n]{4}";

// the data to split...
string content =
  @"LXKM/AD310T0901E/IRNCPK1V53411100/006 13-08-19 03:00:11
  8917(7475) OMT-01/ITMTAC 2893/06189

  TRAFFIC MEASUREMENT : TRUNK GROUP 13-08-17 00:15

  DATA QUALITY : SECURE

  TGNO : VLX22 VLX27 VLX281 V100K
  OPMODE/TGRPTYP : BW BW BW BW
  AVAILABILITY :
  --------------------+---------+-------+-------+-------+-------+-------
  CC:I 3 59 1 50
  TC:I (DERL) 4 31 2 62
  CCS WITH ANSWER:I 4 40 1 35
  TC ANSWER:I (DERL) 3 30 2 47




  LXKM/AD310T0901E/IRNCPK1V53411100/006 13-08-19 03:00:15
  8917(7475) OMT-01/ITMTAC 2893/06189

  TRAFFIC MEASUREMENT : TRUNK GROUP 13-08-17 00:15

  DATA QUALITY : SECURE

  TGNO : V7BSTD
  OPMODE/TGRPTYP : BW
  AVAILABILITY :
  --------------------+---------+-------+-------+-------+-------+-------
  CC:I 7
  TC:I (DERL) 5
  CCS WITH ANSWER:I 4
  TC ANSWER:I (DERL) 3 ";


// Now split on the basis of the assumed delimiter...
Regex chunk = new Regex(DELIMITER, RegexOptions.IgnoreCase|RegexOptions.Multiline);

// Using LINQ for the fun of it. A simple foreach would work equally well.
var getBlocks = from string s in chunk.Split(content)
                where (!string.IsNullOrEmpty(s.Trim()))
                select s.Trim();

foreach(string block in getBlocks)
{
  Console.WriteLine(block);
  Console.WriteLine(@"{0}///////{0}", Environment.NewLine);
}
 
Share this answer
 
v3
There are a huge number of ways to extract text, but all of them depend on information we don't have: what constitutes the start and end of a "block"?
And the two text samples you show have too many similarities for any guess we make to be successful with actual data.

Which leaves us with this general way to do it:
Read it into an array of strings - one line per string - and assuming you have a complete "block" at the start - count off 19 lines and call that a block. Repeat.

You need to look at a couple of things:

The documentation (if you have any) for the data, which explains which parts are "fixed" and which are variable.
The source of the data to see if there is any addition "Start" or "End" characters which have already been discarded.

Just trying to make a working application based on two samples which hardly differ is a recipe for disaster in production!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900