3 Replies - 310 Views - Last Post: 14 November 2012 - 06:02 PM Rate Topic: -----

#1 mon_e_mons  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 05-October 12

How do I read one record at a time from a file with no delimiters?

Posted 14 November 2012 - 05:33 PM

I have a program that has a textfield that you put a word into. Once you've typed the word you press a button labeled "Write" and it appends the word to a text file. There are no delimiters between words that you enter into this text file. So if you typed in "apple" then "orange" then "banana" it would show as "appleorangebanana" in the text file. I also have a button labeled "Read" that is supposed to place one word from the text file at a time into the textfield. So here's my question: How do I use substring to recognize where one word ends and the other begins? Also I can't have it look for capital letters because it should all be lowercase.

Is This A Good Question/Topic? 0
  • +

Replies To: How do I read one record at a time from a file with no delimiters?

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,438
  • Joined: 20-September 08

Re: How do I read one record at a time from a file with no delimiters?

Posted 14 November 2012 - 05:37 PM

Quote

There are no delimiters between words that you enter into this text file
Then it can't be parsed. Use linefeeds
Was This Post Helpful? 0
  • +
  • -

#3 mon_e_mons  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 05-October 12

Re: How do I read one record at a time from a file with no delimiters?

Posted 14 November 2012 - 05:46 PM

View Postg00se, on 14 November 2012 - 05:37 PM, said:

Quote

There are no delimiters between words that you enter into this text file
Then it can't be parsed. Use linefeeds


See that's what I thought but it's something a couple people have already figured out. Maybe it IS allowed to be capitalized but it just wasn't demoed like that for us. In which case you would just use a for loop and if to charAt everything until you get to a character with the unicode value of a capital letter.

Well thanks for confirming for me that under those circumstances it is impossible. Must be that the first letter can be uppercase.
Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2720
  • View blog
  • Posts: 11,438
  • Joined: 20-September 08

Re: How do I read one record at a time from a file with no delimiters?

Posted 14 November 2012 - 06:02 PM

Yes. You could do it with first letter capitalization

Pattern p = Pattern.compile("([A-Z][a-z]*)");


Then use Matcher.find

This post has been edited by g00se: 14 November 2012 - 06:03 PM
Reason for edit:: typo

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1