Know if there is a number within a variable

2

In a variable I keep a number that is in my Oracle DB can be 236578898 but I just need to know if it brings the 2365 to perform an operation, account1 is where I keep the number

if (int.Parse(cuenta1) == 2365) {
    //int valor1 = Int.Parse(TBRete.Text) + Int.Parse(TBRetenAsum.Text) - Int.Parse(textBox4.Text);
    //TBTotal1.Text = valor1.ToString();
} else {

}
    
asked by Saul Salazar 10.08.2018 в 17:10
source

2 answers

2

Assuming that the variable to verify is of type string , you can use StartsWith :

Example:

string variable_a_validar = "236578898";

if (variable_a_validar.StartsWith("2365")) 
{
   // Agregue aquí la lógica.
}
    
answered by 10.08.2018 / 17:31
source
1

If you are interested in validating both, that is at the beginning and that contains the number completely, I recommend using the IndexOf by which it is necessary to convert int to string .

string c = cuenta1;

if(c.IndexOf("2365") == 0)
{
  // Ejecutamos la secuencia de instrucciones.
}

I hope I help you.
Greetings.

    
answered by 10.08.2018 в 17:27