Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Extracting Numeric Data From Text String
Message
 
À
20/03/2013 05:36:55
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01568837
Message ID:
01568860
Vues:
62
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform