i was wondering if there is a loop that can help me fix myproblem so i have a li
ID: 3613733 • Letter: I
Question
i was wondering if there is a loop that can help me fix myproblemso i have a line that im trying to break up into "tokens" orindividual sections so im using String tokenizer but i have aproblem this is the line im reading.
insert Lana Lovetofly:14.24:2233:v
its a command with a first and last name, time, ticket #, and mealplan so when i use string tokenizer and print i get this
insert
Lana
Lovetofly:14.25:2233:v
what i want is
insert
Lana
Lovetofly
14
25
2233
v
is there a way to go into the line with a loop to go through theline and replace the period and colons with spaces. Thesyntax will always be the same if there is a different person ortime the punctuations remain in their positions. Any helpwould be appreciated.
Explanation / Answer
You can replace the period and colons withspaces using the replaceAll method of String. String input= "insert LanaLovetofly:14.24:2233:v"; input = input.replaceAll("[.:]", " "); Note: I used regex in the above example toreplace both colons and periods with onestatement.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.