In java how to identify that the provided string ends with newline character or not?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A newline is an OS-dependant concept. On Unix it’s one character (linefeed – U+000A), on Windows it’s two characters (carriage return + linefeed, U+000D U+000A), it could be ven the newline character (NEL, U+0085, which I think may be used by some mainframes).
Some regular expression engines accept
\Rto mean a newline. Tom Christiansen defines\Rfor Java as the following:at this answer.
Then, you would use a regex like
\R$, or, in Java\\R$, to mean “ends in newline”.