Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Extracting Numeric Data From Text String
Message
 
To
20/03/2013 05:36:55
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01568837
Message ID:
01568860
Views:
61
You can try something like this (I just did it quickly so the regular expression I am sure can be bettered, and you can customize it if there are more lines that you are not showing us
local loReg, lcString, loMatches, loMatch, loSubmatch

clear

text to lcString noshow flags 1 pretext 1 + 2 + 4
F5 B (Total Charges)390 478 w
F5 B (Total Chg)390 478 w
F5 B (Total Chrgs)390 478 w
endtext

loReg			= CreateObject('VBScript.RegExp')
loReg.Pattern		= '.*(\(Total cha?r?g?e?s?\)(\s?390)\s)(\d+)\s?w'
loReg.Global		= .t.
loReg.IgnoreCase	= .t.
loMatches		= loReg.Execute(lcString)
if loMatches.Count > 0
	for each loMatch in loMatches
		loSubmatch	= loMatch.SubMatches.Item(2)
		? 'Total charges:', loSubmatch
	endfor
else
	? 'No matches found'
endif
[Update]

By the way, I forgot to say that you should replace the TEXT ENDTEXT with lcString = FILETOSTR('Your File')

[Update 2]
Just noticed that I called the variable loSubmatch instead of lcSubmatch...
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform