Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clean line breaks in VPF9SP2 1

Status
Not open for further replies.

RobertdeWild

Programmer
Sep 24, 2014
1
US
I am looking for a third party tool (either shareware, freeware or even purchase) or an algorithm or VFP class I can use to create clean line breaks in text I need to output.
E.g. I need to limit output text to, for instance, 30 characters wide given an input line of text.
It's easy enough to cut the line in 30 character segments but I don't want to cut a word in half and have it continue on the next line unless it is clean and appropriate with a hyphen.
I don't want to reinvent the wheel if this is available. Has anyone encountered such a tool?
Many thanks!
Robert.
 
Any of the controls with a 'Word Wrap' property will break the sentences at spaces, but I don't know of any editing tool that will hyphenate words. For instance, the 'Field' report control with "Stretch with overflow" checked.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
It's pretty easy (and built-in).

Code:
lcText = [Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.]

lnWidth = 30

Create Cursor TempTable (MyMemo M)
Append Blank

Replace MyMemo with m.lcText

Set Memowidth To lnWidth
For lnCount = 1 to Memlines(MyMemo)
	?Mline(MyMemo,lnCount)
Endfor
 
Oh, and to get the best performance (this can bog down with REALLY big memo fields), check out the _MLINE system memory variable. It isn't documented very well but it only takes a minute or so of fiddling with it to get what it does.
 
The algorithm Dan is proposing, can be applied to memory variables.

Code:
CLEAR
lcText =[Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.]
* A short text split into rows of maximum 20 chars
lnWidth = 20
lcFinalText=""
Set Memowidth To m.lnWidth
For lnCount = 1 to Memlines(m.lcText)
	lcFinalText=m.lcFinalText+Mline(m.lcText,m.lnCount)+CHR(13)
Endfor 
MESSAGEBOX(m.lcFinalText)


* A long text split into rows of maximum 200 chars
FOR lni=1 TO 10
	lcText=lcText+lcText
NEXT
?"String length=",LEN(lcText)

lnWidth = 200
lcFinalText=""
Set Memowidth To m.lnWidth
For lnCount = 1 to Memlines(m.lcText)
	lcFinalText=m.lcFinalText+Mline(m.lcText,m.lnCount)+CHR(13)+CHR(10)
Endfor 
?m.lcFinalText

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
To implement hyphen and to accept words longer than 30 characters without hyphens, you can use ALINES()
Code:
CLEAR
lcText =[Lorem ipsum dolor sit amet, con-sectetur averylongwordwithmorethan20characterslong adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad ]
lcText =m.lcText +[minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.]
lnWidth = 20
lnWrds=ALINES(laWrds,lcText,2+16,' ',',','...','.','!','?',';',':',CHR(13),CHR(10),'-') && up to 23 Parsechars

lcFinalText=""
lcCurrRow=""
For lnCount = 1 to lnWrds
	IF LEN(m.lcCurrRow)+LEN(laWrds(m.lnCount))<=m.lnWidth 
		lcCurrRow=m.lcCurrRow+laWrds(m.lnCount)
	ELSE
		lcFinalText=m.lcFinalText+m.lcCurrRow+CHR(13)
		lcCurrRow=laWrds(m.lnCount)
	ENDIF
ENDFOR
IF !EMPTY(m.lcCurrRow)
	lcFinalText=m.lcFinalText+m.lcCurrRow
ENDIF
MESSAGEBOX(m.lcFinalText)


Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top