T
T
tr1ck12020-06-02 15:10:48
Java
tr1ck1, 2020-06-02 15:10:48

How to parse filename in java (groovy)?

Hello everyone, there is a certain file name from numbers and letters of the ddddyy_name.xls format. You need to count the first 4 digits and the second two to use them in the code. How to do it?
I do it like this:
String year = new String(p_filename.substring(1,4));
String month = new String(p_filename.substring(5,6));

But it doesn't come out. What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lyoshik, 2020-06-02
@Kot1que

String filename = "ddddyy_name.xls";
String year = filename.substring(0, 4);
String month = filename.substring(4, 6);

indexes from scratch. The first turns on, the second does not turn on.
It also makes no sense to wrap in new String- a new object is returned.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question