` Extracting strings from text (Ray Goudie ) - Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Icetips Article

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Par2: Extracting strings from text
2001-11-25 -- Ray Goudie
 
>What would be a smart way loop through a textfield (CSTRING(4001)) >extracting 80 character long rows and avoiding to split words? I had to do the same thing, a number of years ago. Here is some quick-and-dirty code that will achieve what you are looking for. It only splits on spaces. --- ROW_WIDTH equate(80) textField cstring(4001) rowText cstring(ROW_WIDTH + 1) textLength ushort startPosition ushort ndx ushort code !!! textField gets set somehow. textLength = len(textField) startPosition = 1 endPosition = ROW_WIDTH loop !!! Fetch default row width. rowText = sub(textField, startPosition, ROW_WIDTH) !!! Consider the first character of the next row. if textField[startPosition + ROW_WIDTH] <> ' ' !!! Reduce length of row while the last character of the current row is not a space. !!! Any characters at the end of the current row belong with characters at the !!! beginning of the next row. ndx = ROW_WIDTH loop while rowText[ndx] <> ' ' ndx -= 1 until ndx = 1 end rowText = clip(sub(rowText, startPosition, ndx)) !!! To clip trailing space(s). do processRow !!! Set start position for the next row. startPosition += ndx until startPosition > textLength --- Hope I didn't miss anything.


Today is April 24, 2024, 7:47 pm
This article has been viewed 35110 times.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: