• Post Reply Bookmark Topic Watch Topic
  • New Topic

parseInt for using a blank line for sentinel  RSS feed

 
Joshua Amy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm attempting to set the sentinel in my program as a blank line, but I'm unsure how to go about it except to say that I feel certain parseInt is involved in the process. Can anyone explain to me how to use a blank line for a sentinel?

 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You can’t use parseInt because that requires a String which represents an int. If you want to use a blank line as a sentinel, you can use its length() method, or there is a new (Java6+) method in the String class called isEmpty(). If the length is 0 or the String is empty, then you have a blank line. You can use the trim() method on a line which starts or ends with whitespace, to shorten it.
 
Joshua Amy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for this!



Campbell Ritchie wrote:Welcome to the Ranch

You can’t use parseInt because that requires a String which represents an int. If you want to use a blank line as a sentinel, you can use its length() method, or there is a new (Java6+) method in the String class called isEmpty(). If the length is 0 or the String is empty, then you have a blank line. You can use the trim() method on a line which starts or ends with whitespace, to shorten it.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!