User function: OnlyNumbers ()

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

User function: OnlyNumbers ()

Post by Claudio Ricardo »

Hola a todos !!!
Necesitaba extraer sólo los números contenidos en un string leído de un label escrito por otra función:
GetProperty ("Panel_Articulos", "Label_Panel_Arti_RegNo", "Value") -> Puede contener:
"Registro número: 123" o "La base de datos contiene 24518 artículos." o "Seleccionados 6 artículos."
Lo solucioné así y ya me queda la función de usuario, y la comparto.

Hello everyone !!!
I needed to extract only the numbers contained in a string read from a label written by another function:
GetProperty ("Panel_Articles", "Label_Panel_Arti_RegNo", "Value") -> May contain:
"Record number: 123" or "The database contains 24518 articles." or "Selected 6 articles."
I solved it like this, and share:

Code: Select all

LOCAL nReg := OnlyNumbers ( GetProperty ("Panel_Articulos", "Label_Panel_Arti_RegNo", "Value"))

Code: Select all

//  Funcion OnlyNumbers (cString) Retorna sólo los números contenidos en la cadena
//  Devuelve tipo numérico

Function OnlyNumbers (cString)

LOCAL cOut := ""

	If Pcount () == 0 .OR. Empty (cString)

		Return Val ("0")
		
	EndIf
	
	For i := 1 To HMG_Len (cString)
	
		If Hb_UsubStr (cString, i, 1) $ "1234567890"
		
			cOut += Hb_UsubStr (cString, i, 1)
			
		EndIf
		
	Next

Return Val ( AllTrim ( cOut ))
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
JALMAG
Posts: 265
Joined: Sun Jan 10, 2010 7:05 pm
DBs Used: DBF, MariaDB
Location: España - Spain

Re: User function: OnlyNumbers ()

Post by JALMAG »

¡Gracias! Claudio
Post Reply