• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem on Counting Characters

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,



Input: JavaRanch // 9 + 1(for '\n')
But Output: 11


1> What is the 11th character? or is there any '\0' character?
2> Whether the read() used here, read characters from the keyboard BUFFER until NewLine Character is given ?


With respect,
Anand Damodaran

 
Anand Damodaran
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I found that characters '\u000D' - int value 13 and '\U000A'- int value 10(for '\n') were appended to the array of characters.

i.e., JavaRanch\u000D\U000A ,

so that i get 11.

What is the character value for \u000D? i get NewLine. is that True?


With respect,
Anand
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anand Damodaran wrote:What is the character value for \u000D? i get NewLine. is that True?


I think so, but the reason you're getting two characters (almost certainly) is that you're running the program on Windows, which uses the CRLF form for an end-of-line ('LF' stands for 'line feed' which, as I recall, is the same as a Unix newline).

Instead of using an InputStream, which is very low level, why not just use a Scanner (java.util.Scanner) and read in a line at a time? Then you won't have any of those annoying control characters to worry about.

Winston
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Agree: the read() methods are low level and are not at all nice to work with.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And if that doesn't confuse you, consider this: http://weblogs.java.net/blog/tomwhite/archive/2005/03/counting_charac.html. Counting characters is actually more complicated if you can't rule out arbitrary characters.
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic