Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Numeric string or not?
Message
 
À
21/03/2001 19:26:14
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00487462
Message ID:
00487492
Vues:
9
This was only tested with a few character strings and positive and negative numbers, but try
? MyString = transform(val(Mystring))
If the result is true, then MyString was a valid numeric value. Any non-numeric characters will break the "Val()" function and it won't transform back to the same string.

If you have leading blanks to contend with you will need to add alltrim() to the original string.
? allt(MyString) = transform(val(Mystring))
I may have missed something obvious here, but it's quick for 'ordinary' strings.

HTH
Barbara

>Is there a quick way to determine if a character string represents a legal numeric string (contains only digits and maybe a sign or .)?
>
>I've tried using type(),vartype() and evaluate(), but they don't give me quite the right thing.
>
>Suppose I have a variable NorC.
>
>If it contains the string '1.2' I want mytypefunc(NorC) to return 'N'
>If it contains the string 'A.1' or '1.A' I want mytypefunc(NorC) to return 'C'
>
>EVALUATE('NorC') returns a character string in both cases.
>EVALUATE(NorC) returns a numeric value in 1st case but gives an error in the second case.
>
>Combinations of vartype(),type() and evaluate() do not give what I want.
Barbara Paltiel, Paltiel Inc.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform