4gl code for breaking apart a sentence

Posted by Admin on 28-Dec-2006 08:32

I am having difficulty formatting out the 4GL code that would help me break apart a sentence into 3 different fields. i can't substring since i don't want it to cut a word. it is probably easy but i can't find an example.

thanks for any help

All Replies

Posted by Tim Kuehn on 28-Dec-2006 08:46

On PSDN's "Code Share" and the PEG utilities page (www.peg.com/utilities) is a xref2tt.sp parser. In the xref2tt.sp program is a routine for breaking apart space-delimited strings into the component pieces.

Give that a try and see if it helps.

Posted by jtownsen on 28-Dec-2006 10:56

We kinda need a little more information about what you're trying to achieve, but I imagine it might be something like: the 3 fields are, say "X(25)", but the sentence is longer, eg: "This is the example sentence to be split into 3."

In this case, if you used vcSent2 = SUBSTRING(vcSent, 1, 25), you'd get vcSent2 = "This is the example sent", which of course cuts into a word. If you then used something like R-INDEX(vcSent2, " "), you could sort it out fairly easily.

...but then again, maybe you are looking for something completely different...

Posted by Thomas Mercer-Hursh on 28-Dec-2006 11:37

Do you need something other than ENTRY(N, Sentence, " ")?

Posted by Admin on 28-Dec-2006 14:59

oops, sorry, new at this. i am trying to take a field that is 135 chars, (it is a statute description. " EMBEZZLEMENT-MISAPPLY OF LOAN FUND" etc, etc) and break it into 3 fields - the form i am using is only 45 chars wide. so i don't want to split any of the words if i can help it. thanks.

Posted by Thomas Mercer-Hursh on 28-Dec-2006 15:23

So, it sounds like you could do this with ENTRY()

Posted by akjump on 14-Feb-2007 09:32

lcovay

This code is a little dirty, but it does the trick (if I understand you correctly):

***********************************************

DEFINE VARIABLE lvSentence AS CHARACTER NO-UNDO.

DEFINE VARIABLE lvWord AS CHARACTER NO-UNDO.

DEFINE VARIABLE lvSeperate AS CHARACTER NO-UNDO EXTENT 3.

lvSentence = "This is a sentence that needs to be split into 3 seperate sentences, without causing a split in the middle of any of the words!".

DO WHILE lvSentence NE "":

lvWord = ENTRY(1, lvSentence, " ").

IF LENGTH(lvSeperate[1]) + LENGTH(lvWord) LE 45 THEN

lvSeperate[1] = lvSeperate[1] + MINIMUM(lvSeperate[1], " ") + lvWord.

ELSE IF LENGTH(lvSeperate[2]) + LENGTH(lvWord) LE 45 THEN

lvSeperate[2] = lvSeperate[2] + MINIMUM(lvSeperate[2], " ") + lvWord.

ELSE IF LENGTH(lvSeperate[3]) + LENGTH(lvWord) LE 45 THEN

lvSeperate[3] = lvSeperate[3] + MINIMUM(lvSeperate[3], " ") + lvWord.

lvSentence = TRIM(SUBSTRING(lvSentence, LENGTH(lvWord) + 1)).

END.

MESSAGE lvSeperate[1] SKIP lvSeperate[2] SKIP lvSeperate[3]

VIEW-AS ALERT-BOX INFO BUTTONS OK IN WINDOW ACTIVE-WINDOW.

***********************************************************

Hope this helps!!

Andy

This thread is closed