*** ***
Escape sequences aren't translated until after incidental space stripping
Mikalai Zaikin wrote:Please check the JEP: https://openjdk.org/jeps/378
Specifically this part:
Escape sequences aren't translated until after incidental space stripping
So, first the space literal is stripped, making ******, then \s inserted, which gives *** ***
Mikalai Zaikin wrote:Sorry, I don't know what the book says, I explained the code behavior.
Anil Philip wrote:
Mikalai Zaikin wrote:Sorry, I don't know what the book says, I explained the code behavior.
Unfortunately, I cannot post a screenshot because Campbell said it is not allowed to post any screenshots on this forum.
Anil Philip wrote:In the table, it says \s is:
String:
Two spaces (\s is a space and preserves leading space on the line)
Textblock:
Two spaces
String:
Two spaces (\s is a space and preserves leading space on the line)
Textblock:
Two spaces
Ron McLeod wrote:
Anil Philip wrote:
Mikalai Zaikin wrote:Sorry, I don't know what the book says, I explained the code behavior.
Unfortunately, I cannot post a screenshot because Campbell said it is not allowed to post any screenshots on this forum.
If I had the book, I would transcribe the text from the printed-page/image and post it here.
As far as I can see this is consistent with what Mikalai already posted. And versions of the code which don't include \s result simply in ******, which I believe is also consistent. And it agrees with what Mike just said too.*** ***
Paul Clapham wrote:When I use this code instead: (note the spaces inserted after \s)the same output appears:
As far as I can see this is consistent with what Mikalai already posted. And versions of the code which don't include \s result simply in ******, which I believe is also consistent. And it agrees with what Mike just said too.*** ***
Anil Philip wrote:But why does the book say "Two spaces" ?
The book wrote:_\s - Two spaces (\s is a space and preserves leading space on the line)
Ira Go wrote:
Anil Philip wrote:But why does the book say "Two spaces" ?
I have the book. It is very unfortunate that it is very hard to see/notice a white space before the \s. At least the comment for the String part mentions that "leading space".
Anil Philip wrote:
No, The cord is not from the
Ira Go wrote:
The book wrote:_\s - Two spaces (\s is a space and preserves leading space on the line)
Mike Simmons wrote:I note that in that page about not posting images, the first thing it talks about is how users need an extra step to download images, which many users are reluctant to do. That doesn't seem to describe the current user experience.
Mike Simmons wrote:I note that in that page about not posting images, the first thing it talks about is how users need an extra step to download images, which many users are reluctant to do. That doesn't seem to describe the current user experience.
Paul Clapham wrote:The key part about the "policy" here is, people are posting screenshots which contain text and code. That means that anybody else who wants to work with that code has to retype the code, with all of the errors which might arise from that. So that's an impolite thing for a poster to do, making everybody else retype the code when they could just have copy-pasted it into a forum post.
Notice also that the "policy" doesn't say "No screenshots". It's here: The page in question. It says "Post Text Not Screenshots" and goes on to explain why screenshots can be Not Nice. I don't think it's too much to ask, that. I also think it's not hard to understand.
Anil Philip wrote:No, The cord is not from the book. I wrote the code to test out what the book was saying. There is just a table in the book that says "two spaces" which I quoted.
Mike Simmons wrote:
So is this in the part labeled String (or String literal maybe), or text block? Anil previously showed this as the explanation under "String", but the question is why they talk about two spaces under "text block". If indeed that's what the book says...
I wonder if the book was talking about a slightly different situation, if you have \s followed by something else?
Formatting | Meaning in regular String | Meaning in text block |
---|---|---|
\s | Two spaces (\s is a space and preserves | Two spaces |
leading space on the line) |
Escape sequences aren't translated until after incidental space stripping, so \s can act as fence to prevent the stripping of trailing white space. Using \s at the end of each line in this example guarantees that each line is exactly six characters long:
The \s escape sequence can be used in text blocks, traditional string literals, and character literals.
Ira Go wrote:I have the book. It is very unfortunate that it is very hard to see/notice a white space before the \s.
Mike Simmons wrote:Thanks, Ira. Combining that with your previous statement
Ira Go wrote:I have the book. It is very unfortunate that it is very hard to see/notice a white space before the \s.
It... sort of makes sense. Except not really. First, it seems Anil saw it as a space after the \s, while you saw one before. Moreover, whether it ends up as one space or two (or more) in a text block would depend entirely on whether there is any other non-whitespace, text either before or after. Which seems to be information entirely lacking from the presentation. I'm not sure there's anything useful to salvage from that table - they would have been better to leave it off entirely.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2