Parse RTF or Text Control into several lines including spaces


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Michael,



Part of my confusion is why you are working on EDI out of a text box. I really don't know what part you are not getting either based on the comments on this thread so far.



So let me tell you what I generally do when working with EDI. In a very simple sample, the Split is an awesome feature and I will use it. However, when parsing EDI, it is generally best to create a reader. If you are reading out of a file, then I would create a FileStream then a StreamReader off of that file stream. You can also use a StringReader which would look something like this:





string line;

string[] segments;



System.IO.StringReader reader = new System.IO.StringReader(MyTextBox.Text);



line = reader.ReadLine();

while(!string.IsNullOrEmpty(line))

{

//-- Parse the line here. You may want to use a split at this point for segment delimitters (i.e. a pipe [|])

segments = line.Split(new char[] { '|' }, StringSplitOptions.None);



//-- Determine the segment type

switch(segments[0])

{

case "OBX":

{

//-- Place your OBX logic here

} break;

}



//-- Read the next line

line = reader.ReadLine();

}

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
I must not be asking my questions properly because you aren't answering them and just keep saying the same things over and over again so I will bow out and let someone else take a shot at it.



Good luck. Smile



Michael Reese
Michael Reese
StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)
Group: StrataFrame Users
Posts: 235, Visits: 1.6K
Ok,



I need to read the textbox. Parse the contents into several lines each in the obx segment above. I will like to have it read the text object and set the line or row length and include carriage returns.



Thanks



Michael



Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Stretching out your sample on my big monitor it seems to be just a delimited file using a pipe seperator. What happens if you try the example of the split() I showed you? If that doesn't work try it with a combination of Chr(13) and chr(10)



You should end up with a string array with one line per item.



Hard to tell how it is structured from the sample but there should be some rules as to where lines break.
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Not sure what you mean by "the lines and breaks and spaces between the lines."



The same you posted is hard to decipher because it wraps and we don't know where the lines break. What is the breaking char? Chr(10) chr(13) or a combination? Are there blank lines? What determines where a line begins and ends?



If you can give some very specific answers about the structure parsing it will be pretty easy.



( see my previous question - in the example you posted, how many lines would that break into? )

Michael Reese
Michael Reese
StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)
Group: StrataFrame Users
Posts: 235, Visits: 1.6K
I need to see the lines and and breaks and spaces between lines. Do you have a code example?



Thanks
Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)Advanced StrataFrame User (922 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Be aware the .Split() thing has a lot of flexibility.



Should your example yield 7 lines or is there a fixed length to the line and you want to slice it into even pieces?

Michael Reese
Michael Reese
StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)
Group: StrataFrame Users
Posts: 235, Visits: 1.6K
Ok, thank,



Yeah, My message is generating but I need to clean it up.



Thanks Guys!





MSH|^~\&|Some Sending APP|Sending Facility|EHTESTER2005|SLU|20100308||^MDM^T10|E66F6810E8ED4304AD6F417F561906AE|

EVN|MDM|

PID|1|23455|23455||Smith^Joe ||19560806|M|Joey||10 Wiillington Drive^^Roselle^NJ^07203-1873|USA|(909) 555-2344|(908) 552-1234||S||23455|141-52-3122|

PV1|1|O|ENDO - DOB 2||||SILALA1^SILVERBERG^ALAN^B||||||||||||1|||||||||||||||||||||||||20100306|

TXA|1|PN||20100308|SILALA1^SILVERBERG^ALAN^B^^^^^^^^^|||||SILALA1^SILVERBERG^ALAN^B^^^^^^^^^|001^Test^Test^^^^|^^10821954|^^10821954||||AV|

OBX|1|TX|||All the world's a stage, and all the men and women merely players; they have their exits and their entrances, and one man in his time plays many parts, his acts being seven ages.|

OBX|2|TX|||

|

OBX|3|TX|||

To be, or not to be, that is the question: whether 'tis nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles and by opposing end them. To die-to sleep, no more; and by a sleep to say we end the heart-ache and the thousand natural shocks that flesh is heir to: 'tis a consummation devoutly to be wish'd. To die, to sleep; to sleep, perchance to dream-ay, there's the rub: for in that sleep of death what dreams may come, when we have shuffled off this mortal coil, must give us pause-there's the respect that makes calamity of so long life. For who would bear the whips and scorns of time, th'oppressor's wrong, the proud man's contumely, the pangs of dispriz'd love, the law's delay, the insolence of office, and the spurns that patient merit of th'unworthy takes, when he himself might his quietus make with a bare bodkin? Who would fardels bear, to grunt and sweat under a weary life, but that the dread of something after death, the undiscovere'd country, from whose bourn no traveller returns, puzzles the will, and makes us rather bear those ills we have than fly to others that we know not of? Thus conscience does make cowards of us all, and thus the native hue of resolution is sicklied o'er with the pale cast of thought, and enterprises of great pitch and moment with this regard their currents turn awry and lose the name of action. |

OBX|4|TX|||

|

OBX|5|TX|||

Shakespeare!|

OBX|6|TX|||

Shakespeare.|

OBX|7|TX|||

Shakespeare?|
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Well, I have lived in the realm of EDI interfaces for a good long while now and this can be a really deep topic in regards to EDI parsing. However, if you are just trying to get the line breaks, then Charles suggestion should work just fine.
Michael Reese
Michael Reese
StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)StrataFrame User (403 reputation)
Group: StrataFrame Users
Posts: 235, Visits: 1.6K
Thanks guys,



I have a text or RTF. I want to extract the text and populate multiple OBX segments with each line (including blank spaces). I have been extracting except that I get bit of a formatting mess like most of the paragrah in one OBX.



not pretty.



Michael
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search