#Im trying to save data to a txt file

1 messages · Page 1 of 1 (latest)

sonic tiger
#

so i am trying to make a diary project and i will put the diary data in the text file and interact with it through GUI but because it is a diary it will have 2 parts date and notes i watched the tutorial and they use readline but i don't want to make a new line to spilt the date part and note part so i put them in a same line now the file reader going to read the line and give me one string how do i split the date and note separated like how do i flag that this part is date this part is note so i can split it to two variables

cyan marlinBOT
#

<@&987246399047479336> please have a look, thanks.

surreal vessel
#

If it's date, space, then entry then you can find the index of the first space using indexOf and split the String using substring. Another alternative is using a Regular Expression, but those are used far too often (they're an expensive tool you shouldn't reach for quite so early).

primal bobcat
#

just parse the line to what u need . Also one huge advice. Do not post stuff like that, it will chase people away and not take u serious at all

sonic tiger
sonic tiger
chrome jasper
#

for example suppose u have the text (x : 123, y - 45) and u want to extract the numbers 123 and 45, then regex could do that for u easily with the pattern \(x[ :-]+(\\d+), y[ :-]+(\\d+)\)

#

or alternatively just the pattern \\d+ being applied multiple times

#

in java this is done using the classes Pattern and Matcher

sonic tiger
chrome jasper
#

i mean, in ur specific case it wouldnt be that difficult

#

for a text like 20/10/2022 life suck, regex could split it into the two parts using: (\\d+/\\d+/\\d+) (.+)

#

but yeah, for this specific string, a simple split on the first space would suffice as well

#

int index = text.indexOf(' ') tells u where the first space is at

#

and then u can just text.substring(0, index) and text.substring(index + 1) or sth like that