Control characters string c #

1

my question is how I can do to control the number of characters, eg when I ask you to enter enrollment you must enter ASD (only 3 characters) and not ASDASF (so it would be wrong)

 Console.Write("Ingrese matricula del vehiculo : ");
                    matricula = Console.ReadLine();
                    if (matricula == "")
                        mensaje = "La matricula es obligatoria\n";
    
asked by Francop 19.07.2017 в 19:30
source

1 answer

3

You can use the property Length to know the number of characters of a String :

Console.Write("Ingrese matricula del vehiculo : ");
 matricula = Console.ReadLine();
 if (matricula == "")
    mensaje = "La matricula es obligatoria\n";
 else if(matricula.Length > 3)
   mensaje = "La matricula solo puede tener 3 caracteres";
    
answered by 19.07.2017 / 19:32
source