The following program reads a txt file line by line:
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(origin),"ISO-8859-1"));
String strLine;
while ((strLine = br.readLine()) != null) {
if(strLine.contains("Fecha de Emision: ")){
String date = strLine.substring(84,93);
String[] parts = date.split("/");
try{
int day = Integer.parseInt(parts[0]);
if(day < 10){
SimpleDateFormat format = new SimpleDateFormat("MM/dd/YYYY");
String dateString = format.format(new Date(date));
String newDate = strLine.replace(date, dateString);
writer.write(newDate+"\n");
} else{
writer.write(strLine+"\n");
}
} catch(NumberFormatException nfe){
System.out.println("Problema al parsear el día de la fecha");
return;
}
} else{
writer.write(strLine+"\n");
}
}
br.close();
If in the line you are reading you find the String "Date of Issuance" what should come next is the date itself (EXAMPLE: 06/12/2018). I'm assuming the date is between positions 84 and 93
String date = strLine.substring (84,93);
but it's not always like that.
What is fixed is that the date always starts two spaces after the String "Issue Date".
Question:
How do I tell my program to do that? In other words, move two characters to the right from "Date of Issuance" to be able to validate the date format and other things that I have already done !!!
Thank you very much:)