Char values of 13 and 10 in java

I’m doing some compiler stuff for json, and I ran into a bit of a problem.

There seems to be 2 values in my string that I don’t understand. At first, I thought that 13 and 10 were “\n” thingy, but it doesn’t seem so.

Values of 13 and 10 are both new line symbols… I mean, I’m kinda lost here… What do 13 and 10 represent? Should I just count both of them as new line symbols?

Unix had “\n”, Mac had “\r”, so Microsoft thought: we need to make our data files incompatible, so people will have to choose an OS and stick with it, so we use “\r\n”.

“\n” = new line
“\r” = carriage return

for their meaning, look at typewriters: you return the carriage, and at the last moment it triggers the drum to be rolled to go to the next line. Technically, Microsoft has the most accurate digital representation of how a typewriter works (hurray!), but as their programs do not support a carriage return without a new line, or a new line without a carriage return, it’s hard to defend – except for being intentionally incompatible with their competition, just like they tried succesfully with MSIE - although they had to back paddle the last decade. Ramble. Ramble.

13 is carriage return or ‘/r’
10 is new line or ‘/n’

Both are essentially the same thing in concept, but some word processors don’t accept the /n while others don’t accept the /r. Which forced me to add a very ugly /r/n at the end of all my documents that I generate in code :stuck_out_tongue:

Actually in days of yore the M.S. format made sense. You could just pipe the raw data to your printer and you got what you expected instead of a big mess.

These days with at least half a dozen abstraction layers between our code and hardware, it’s easy to forget people actually did raw I/O with a printer, back then.

I use \r all the time:

System.out.print("Items done: " + index + '/' + items.length + '\r');

Gives a single line of output with an updating index - prevents scroll blindness sometimes.

Oh. Thank you, that’s incredibly helpful!

If you put random \r in Strings and they get set to the console, you can confuse the hell out of people debugging your code. I once spent an afternoon convinced there was an error in the JVM. In the end I had to write out the string as a list of bytes to see what was going on…

Offtopic:

would anybody know the reason for Microsoft using ‘’ as a directory separator character? To me it screams ‘deliberate incompatibility’, once again… :persecutioncomplex: especially as it interferes with the escape character.

Long story short…IBM used “/” to indicate command line switches.

Short story long can be found here. 8)

[quote]But there was a problem. They couldn’t use the *nix form of path separator of “/”, because the “/” was being used for the switch character.
[/quote]
So we take away from this that their command parser was a quick and dirty hack.

I wouldn’t say that it was a quick and dirty hack. It just wasn’t very a very forward thinking API.

Let’s be honest though, a lot of technology comes down to solutions that work for the moment, and while I’m not a huge fan of Microsoft, I can hardly hang that albatross solely on their neck. Every developer has at least a slight stench of fowl hanging around them most of the time. Come, let me tell you the rime of the ancient code mariner. :stuck_out_tongue:

Forward thinking? What was the point of being the same as unix at the time? I want to think the apple 2 file separator was . I can’t remember other systems at the time.

The article suggests that they wanted to use ‘/’, but couldn’t because their command parser was hardcoded to interprete any ‘/’ as a switch.

Not quite…

This is more IBM than Microsoft in this case. IBM was the customer, and Microsoft was the contractor.