× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I am confused as to the problem.

D TextField 256
D LongField ds D ARRecords 40 dim(7)
....
C LongField = TextField
* Write 10 records:
C for i = 1 to 10
C eval RecField40 = ARRecords(i)
C write Record
C endfor

Obviously this is pretty simplistic, but won't it (or something like it) do the job more easily that a multiple occurrence data structure?


James Perkins wrote:
Arron,
If you are just looking for a way to split a long string try this procedure.
I haven't heavily tested it and it's not in production for anything, but it
seems to work.

* Split a string into chunks and wrap by word if requested
P splitString B
D splitString PI 10i 0
D inString * value options(*string)
D outString * value
D len 10i 0 const
D wordWrap n const options(*nopass)
*
D lastPos s 10i 0 static
D startPos s 10i 0
D endPos s 10i 0
D string s 65535a varying
D pReturnString s *
D returnString s 65535a based(pReturnString)
*
/free
// Check to see if this is a reset
if (lastPos < 0);
return
-1;

endif;


// Load the work
string
%len(string) =
%len(%str(inString));
string =
%str(inString);


// Set up the return string and default it to
blanks
pReturnString =
outString;
%subst(returnString : 1 : len) =
*blanks;


// The start position should be the end position plus
1
startPos = lastPos +
1;
endPos =
0;
// Add the length to the end
position
lastPos +=
len;


// Return the chunck if we are not wrapping by
words
if (%parms() <> 4 and %addr(wordWrap) <> *null and not
wordWrap);
// Check the start end end
points

if (startPos >
lastPos);
lastPos =
-1;
endPos =
-1;

else;

endPos = (lastPos - startPos +
1);

endif;

else; // Word wrap is
active
// If the string contains no blanks, return the whole
string
if (%scan(' ' : string) > len or %scan(' ' : string) =
0);
lastPos =
-1;
endPos =
-1;

endif;



// Length of the string passed is the same incoming
length
// return the incoming
string
if (%len(string) <=
len);
lastPos =
-1;
endPos =
-1;

endif;



// If the last position is less than 0, something else has
occured
if (lastPos >=
0);


// If the end position is greater than the length of the trimmed
string
// we are
done.
if (lastPos >=
%len(%trimr(string)));
lastPos =
-1;
endPos = (%len(%trimr(string)) - startPos +
1);

endif;
if (endPos <=
0);
// Loop through until we find a
blank
dow (%subst(string : (lastPos + 1) : 1) <>
*blanks);
lastPos -=
1;
if (lastPos <=
0);
lastPos =
len;

leave;

endif;

enddo;
endPos = (lastPos - startPos +
1);

endif;

endif;
endif; // Word wrap
test


// Make sure the starting position is not a positive
number
if (startPos <=
0);
startPos =
1;

endif;


// Set the return string
value
if (endPos >
0);
%subst(returnString : 1 : len)
=
%trim(%subst(string : startPos :
endPos));

else;
%subst(returnString : 1 : len) = %trim(%subst(string :
startPos));

endif;


// Return the length of the return
string
return %len(%trimr(%subst(returnString : 1 :
len)));

/end-free

*
P splitString E

It would work something like this.

dow (splitString(message : %addr(toMessage) :
%len(toMessage) : *on) > 0);
// do something
enddo;

HTH,
James R. Perkins

On Thu, Sep 18, 2008 at 12:21 PM, Aaron Bartell <aaronbartell@xxxxxxxxx>wrote:

Hi all,

I am trying to use regular expressions to take a long text string (from a
browser text box) and "splice" it out to fit into multiple DB2 records
which
are 40 characters long each. I have found articles by Scott Klement and
Bob
Cozzi and they have gotten me pretty far, but I seem to be getting odd
results and am wondering if anybody can see where I might be wrong.

Basically I have an all inclusive program (see below) that hard codes a
long
string. Then I compile the regex and execute it. Both of these steps are
successful but when I loop through it with a FOR opcode I get weird results
where the first entry of regmatch_t is as expected, but the second and the
third aren't what I am expecting. For the second I would expect a starting
string offset different than the first, but it is not. For their third
iteration I get it matching up with a single character.

Any glaring mistakes given my general need?

Aaron Bartell
http://mowyourlawn.com
------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG - http://www.avg.com Version: 8.0.169 / Virus Database: 270.7.0/1679 - Release Date: 9/18/2008 5:03 PM



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.