Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Memo field parsing routine that doesnt break words
Message
De
27/03/2013 04:24:45
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Divers
Thread ID:
01569314
Message ID:
01569327
Vues:
74
>anyone have an easy-to-use routine that returns say the first 150, 200, 250 (etc) chars from a memo field but avoids breaking words in the process? Something usable in a SQL SELECT statement?

Regex comes to mind

I've used a pattern that returns at most 100 chars followed by a word break( \b ie the match must occur on a boundary between a \w and \W)
We know that regex is greedy ( always returns the longest match unless we override that behaviour with greed quantifiers), so the string with the maximum length satisfying the condidtion is returned
*_______________________________________________________________________________	
function regexTest()
	
	local obj,lines
	
	obj = createObject('VBScript.RegExp')
	obj.IgnoreCase = .f.
	obj.Global = .f.
	obj.Pattern = "^.{0,100}(\b|$)"
	
	create cursor Test (field1 M)
	text to lines noshow pretext 3
	I have this new HP LaserJet Pro 400 printer. One word: "Wow". It does some pretty impressive things for under 500.00$. But, there is this little thing I do not like and that is this 
	It does some pretty impressive things for under 500.00$. But, there is this little thing I do not like 
	endtext
	
	local aa[1], naa, line 
	naa = alines(aa, m.lines, 3)
	for each line in aa foxobject
		insert into Test values(line)
	endfor
	
	
	select cast( TestLine(m.obj, field1) as M ) as contents ;
		from Test ;
		into cursor tmp
	
	** =brow()
	
endfunc
*_______________________________________________________________________________
function TestLine(regexObj, s)
	
	local matches
	matches = m.regexObj.Execute(nvl(m.s, ''))
	return	m.matches.Item(0).Value
endfunc
*_______________________________________________________________________________
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform