Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Char values of 13 and 10 in java  (Read 787 times)
0 Members and 1 Guest are viewing this topic.
Offline trollwarrior1
« Posted 2014-05-21 04:28:38 »

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?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 798
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2014-05-21 04:35:10 »

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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #2 - Posted 2014-05-21 04:38:11 »

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 Tongue

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Roquen
« Reply #3 - Posted 2014-05-21 08:42:02 »

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.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 798
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2014-05-21 08:58:00 »

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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ags1

JGO Ninja


Medals: 62
Projects: 3
Exp: 5 years


Make code not war!


« Reply #5 - Posted 2014-05-21 10:21:09 »

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.

Offline matheus23

JGO Kernel


Medals: 107
Projects: 3


You think about my Avatar right now!


« Reply #6 - Posted 2014-05-21 15:23:49 »

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!

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline ags1

JGO Ninja


Medals: 62
Projects: 3
Exp: 5 years


Make code not war!


« Reply #7 - Posted 2014-05-21 17:53:04 »

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...

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 798
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2014-05-22 15:48:24 »

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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #9 - Posted 2014-05-22 15:51:51 »

Long story short...IBM used "/" to indicate command line switches.

Short story long can be found here. Cool

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 798
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2014-05-22 15:59:58 »

Long story short...IBM used "/" to indicate command line switches.

Short story long can be found here. Cool

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.
So we take away from this that their command parser was a quick and dirty hack.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #11 - Posted 2014-05-22 16:51:40 »

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.

Quote
The fact that the "/" character conflicted with the path character of another relatively popular operating system wasn't particularly relevant to the original developers - after all, DOS didn't support directories, just files in a single root directory.

Then along came DOS 2.0.  DOS 2.0 was tied to the PC/XT, whose major feature was a 10M hard disk.  IBM asked the Microsoft to add support for hard disks, and the MS-DOS developers took this as an opportunity to add support for modern file APIs - they added a whole series of handle based APIs to the system (DOS 1.0 relied on an application controlled structure called an FCB).  They also had to add support for hierarchical paths.

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. Tongue

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Offline Roquen
« Reply #12 - Posted 2014-05-22 18:51:42 »

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.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 798
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #13 - Posted 2014-05-22 18:55:42 »

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

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline CodeHead

JGO Knight


Medals: 41


From rags to riches...to rags.


« Reply #14 - Posted 2014-05-22 19:13:19 »

Not quite...
Quote
Here's a little known secret about MS-DOS.  The DOS developers weren't particularly happy about this state of affairs - heck, they all used Xenix machines for email and stuff, so they were familiar with the *nix command semantics.  So they coded the OS to accept either "/" or "\" character as the path character (this continues today, btw - try typing "notepad c:/boot.ini"  on an XP machine (if you're an admin)).  And they went one step further.  They added an undocumented system call to change the switch character.  And updated the utilities to respect this flag.
This is more IBM than Microsoft in this case. IBM was the customer, and Microsoft was the contractor.

Arthur: Are all men from the future loud-mouthed braggarts?
Ash: Nope. Just me baby...Just me.
Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (29 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (79 views)
2014-09-10 06:39:09

Tekkerue (40 views)
2014-09-09 02:24:56

mitcheeb (59 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (36 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!