-3
I’m having trouble finding two patterns inside a java string, given a string. For example:
String str = 021478345231402198408189472328090419790164437663021101996091789834401805198616773422110231220010017325545008091968040901876902511198100789089990090919991753135151210101987;
I know that every 11 digits is a Cpf and every 8 digits after Cpf is a date of birth.
I need to settle this matter
- Given a sequential file, with fixed-size records, containing CPF numbers (11 bytes) followed by birth dates (8 bytes).
Identify:
How many records are there in the file? What is the position of the 3rd record? (Create a formula) List a record per line and separating the fields for
,
I can use Pattern to locate x numbers, but I didn’t understand to find x and y pattern.
tried to do using a substring(0,9)+",";
but he changed the last number by ,
.
This is a college exercise or something?
– Victor Stafusa
That, data structures, we needed a light, we were able to do some things, but not locate right as you ask. adding the , we managed to break it using the split();
– Patrick de Freitas
Each line in the file has 19 characters?
– rray
Create a class that represents the record. 11+8=19. So, create a
for
that separates this string into parts every 19 characters. For each part of 19 characters, you separate the first 11 of the CPF from the last 8 of the date and use them to create an instance of your record and then produce a list of those records. Write over the methodtoString
of this class by placing the result separated by a comma. Finally, you iterate the produced list and give aSystem.out.println
in each item.– Victor Stafusa
so, this is a single line a single Str, I need to break it and find Cpf and rg for example, 02147834523,14021984,
– Patrick de Freitas