Tema: cadenas
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/02/2003, 11:44
drn r
 
Fecha de Ingreso: enero-2003
Mensajes: 39
Antigüedad: 21 años, 4 meses
Puntos: 0
cadenas

Hola

en una variable tipo String tengo:

String fecha="20020224"

yo qiero cortar esa cadena para obtener las siguientes variables:

String anio=" 2002"
String mes ="02"
String dia=" 24"

He probado a hacer

String anio=fecha.charAt(0)+fecha.charAt(1)+fecha.charAt( 2)+fecha.charAt(3);
String mes=fecha.charAt(4)+fecha.charAt(5);

pero me da un error y no me funciona.
El error q me da es:

String mes=fecha.charAt(1);
<----------------->
*** Error: The type of the left-hand side in this assignment, "java/lang/String", is not compatible with the type of the right-hand side expression, "char".


¿Alguien me puede ayudar?