tags:

views:

55

answers:

3

I need to read a block of data from this text. The block starts with the T|DataObject.EShop.Tic.TicVente| line and ends with T|DataObject.EShop.Tic.TicPaiement|.

I only want the lines that start with D between the previous strings.

W|301500120100407213036|

M|SYP||

T|DataObject.EShop.Tic.TicVente|

C|ArtId|ArtRef|PrxInit|QteArt|PrxEntId|TvaId|TvaTaux|RetourId|RetourMagAchat|RetourTicExtIdAchat|RetourDatAchat|PosteNum|TicId|LigNum|PrxAppel|PrxPaye|DatMaj|

D|18250168145|1825016814503131|1690|-1|0934489998|1|0|C|150||20100406000000|1|009700001|1|1690|1690|20100407093455|

D|18250137020|1825013702002161|750|1|1002689999|1|0|||||1|009700001|2|750|750|20100407093455|

D|18260013233|1826001323336111|1990|1|0935689998|1|0|||||1|009700002|1|1990|1990|20100407103918|
T|DataObject.EShop.Tic.TicPaiement|

C|PosteNum|TicId|LigNum|PaieId|Mnt|DevId|MntDev|Info1|Info2|TransId|TransOK|DatMaj|

D|1|009700001|1|01|-940|SYP|-940|||||20100407093455|

D|1|009700002|1|01|4000|SYP|4000|||||20100407103918|
T|DataObject.EShop.Tic.TicVenteAnnulee|

C|PosteNum|Dat|SessId|CliTypId|CliId|UtilId|LotId|ArtId|ArtRef|PrxInit|QteArt|PrxEntId|TvaId|TvaTaux|RetourId|RetourMagAchat|RetourTicExtIdAchat|RetourDatAchat|TicId|LigNum|PrxAppel|PrxPaye|DatMaj|

D|1|20100407105721|0097001|||6|0150010097763|18250040037|1825004003704121|990|1|1002689999|1|0|||||009700004|1|990|990|20100407213033|T|DataObject.EShop.Tic.TicVenteAnnulee|

C|PosteNum|Dat|SessId|CliTypId|CliId|UtilId|LotId|ArtId|ArtRef|PrxInit|QteArt|PrxEntId|TvaId|TvaTaux|RetourId|RetourMagAchat|RetourTicExtIdAchat|RetourDatAchat|TicId|LigNum|PrxAppel|PrxPaye|DatMaj|

D|1|20100407105721|0097001|||6|0150010097763|18250040037|1825004003704121|990|1|1002689999|1|0|||||009700004|1|990|990|20100407213033|
A: 

Well, you could find the first reference of T|DataObject, verify that it is the type you are looking for, then look for the next reference of T|DataObject.

Seems like it's just some simple string manipulation.

Is all of this on a single line or are the object header separated by carriage returns as well?

UPDATE
This is by no means the best way to do this and is just one possible way:

String sRecords = "T|DataObject.Test|C|RecordHeaderId|D|123|D|234|T|DataObject.Test2|C|RecordHeaderId|D|2345|D2366";

// this will split the string into an array on the boundary of |.
// which means you'll have all of item individual items separated out.
String[] sArray = sRecords.Split('|');
List<String> objects = new List<string>();
String obj = String.Empty;

foreach (String s in sArray) {
    // locate the T item which defines a new record definition.  
    // the danger is if your data contains a "T" value somewhere it shouldn't
    if (s.Equals("T") && !String.IsNullOrEmpty(obj)) {
        objects.Add(obj);
        obj = String.Empty;
    }
    obj = String.Format("{0}|{1}", obj, s);
}
objects.Add(obj);

// at this point "objects" hold a list of strings, each defined by the record type.
foreach (String s in objects) {
    listBox1.Items.Add(s);
}
Chris Lively
could u write a code for this cuz i have tried alot and nothin is working :S:S:S !!!??? :s
@user486848: Please try to refrain from using "l33t" or "text" speak or any derivative. Besides sounding like you're 12, a number of people on this site are non-native english speakers and it limits the possible audience for your question.
Chris Lively
okey well thanx iam ganna try it ,and iam just non-native english speaker
+1  A: 

set a flag indicating you are searching for your starting string
read lines until you find your start string (or EOF)
set a flag that indicates you are searching for the closing string
read lines until you find your ending string (or EOF)
when ending string found, set flag that

print all lines read between starting string and ending string

KevinDTimm
+2  A: 

What about Regular Expressions?

You said:

starts in "T|DataObject.EShop.Tic.TicVente|" line

So it will begin with "^T|DataObject.EShop.Tic.TicVente|$"

You said:

T|DataObject.EShop.Tic.TicPaiement|

So it will end with "$T|DataObject.EShop.Tic.TicPaiement|$"

What else do you need? Each line starts with D? OK... try this

Regex rgx = new Regex("^T|DataObject.EShop.Tic.TicVente|$(D[.]*)$T|DataObject.EShop.Tic.TicPaiement|$", RegexOptions.MultiLine);

Or you can easily parse

djechelon
please forgive me if the regex doesn't work on first strike, I hand-wrote it. I'm starting to think that it should be fixed because it literally costraints the lines to start with D, failing in your case. A better regex can be done with the help of other experts, but I hope I put you in the right direction.
djechelon
but if i have new line how can i write the new line pattern