Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Check if a string is a positive number Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Checar si una cadena es un numero positivo 17-May-07
Category
Algorithm
Language
CBuilder All Versions
Views
7
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
RINCON, SALOMON
Reference URL:
			1   
2   //---------------------------------------------------------------------------
3   /* 
4   English: This function receives a chain, Czech character x character to see if it 
5   is possible to be turned to positive number.
6   
7   Spanish: This function receives a chain, Czech character x character to see if it 
8   is possible to be turned to positive number
9   */
10  bool __fastcall TF_Principal::EsNumeroPositivo(String s_cadena)
11  {
12   int i_posicion=0, i_puntos=0;
13   String s_validos = ".0123456789", s_caracter="";
14   bool bl_numero=true;
15  
16   // Si la cadena que recibe está vacia regresa falso
17   //If the chain that receives is vacia it returns false
18   if (s_cadena=="")
19       bl_numero=false;
20   else
21       /* 
22  English:It is crossing the chain that receives and checking if the s_validos 
23  characters that compose it are inside of the chain (it is to say, it takes a 
24  character and Czech if it is a point or a number. If the extraido character of the 
25  s_cadena chain is not in the chain s_validos it returns false
26  Spanish:Va recorriendo la cadena que recibe y checando si los caracteres que la 
27          componen están dentro de la cadena s_validos (es decir, toma un caracter 
28          y checa si es un punto o un número.
29          Si el caracter extraido de la cadena s_cadena no se encuentra en la 
30          cadena s_validos regresa falso
31       */
32       for (int i_x=1;i_x <=s_cadena.Length();i_x++)
33           {
34            s_caracter=s_cadena.SubString(i_x,1);
35            i_posicion=s_validos.Pos(s_caracter);
36  
37            if (i_posicion==0)
38               {
39                bl_numero=false;
40                break;
41               }
42            else
43                /* 
44  English:
45  It means that the extraido character of s_cadena is a point or a number, then Czech 
46  if the character that it is extracting of the s_cadena chain is a point. If it is 
47  thus, increases the accountant that we used to see how many times it appears the 
48  point in the s_cadena chain.
49  
50  Spanish:
51  Significa que el caracter extraido de s_cadena es un punto o un 
52                   número, entonces checa si el caracter que está extrayendo de la 
53                   cadena s_cadena es un punto. Si es así, incrementa el contador 
54                   que usamos para ver cuántas veces aparece el punto en la cadena 
55                   s_cadena
56                */
57                if (s_caracter==".")
58                    i_puntos++;
59  //If there is but of a point in the chain, it returns false
60            // Si hay mas de un punto en la cadena, regresa falso
61            if (i_puntos>1)
62               {
63                bl_numero=false;
64                break;
65               }
66           }
67  
68   return bl_numero;
69  }


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC