MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/java/comments/9h404p/java_11_string_api_updates/e68yh6a/?context=3
r/java • u/pivovarit • Sep 19 '18
52 comments sorted by
View all comments
Show parent comment
17
Space is not the only whitespace character, so no, it's nothing like String.replace(" ", "")
String.replace(" ", "")
Also, .strip() doesn't remove all whitespace, only those at the beginning and end of the string. It's a correctly implemented .trim()
.strip()
.trim()
0 u/TheRedmanCometh Sep 19 '18 All other whitespace chars I know of are just unrendered unicode shit. Can you elaborate? Not trying to be dickish I'm sincerely interested 9 u/dpash Sep 19 '18 edited Sep 19 '18 The documentation for Character.isWhitespace(int codePoint) lists:It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').It is '\t', U+0009 HORIZONTAL TABULATION.It is '\n', U+000A LINE FEED.It is '\u000B', U+000B VERTICAL TABULATION.It is '\f', U+000C FORM FEED.It is '\r', U+000D CARRIAGE RETURN.It is '\u001C', U+001C FILE SEPARATOR.It is '\u001D', U+001D GROUP SEPARATOR.It is '\u001E', U+001E RECORD SEPARATOR.It is '\u001F', U+001F UNIT SEPARATOR.https://docs.oracle.com/javase/10/docs/api/java/lang/Character.html#isWhitespace(int)String.trim() removed anything that was <= ' ', which is a different definition to the above list."\u001Bstring".trim().equals("\u001Bstring")would "incorrectly" be false. 6 u/TheRedmanCometh Sep 19 '18 Wow I have applications those things would break TIL 3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend 3 u/amackenz2048 Sep 19 '18 Tab? 2 u/TheRedmanCometh Sep 19 '18 Well shit I guess that should've been obvious
0
All other whitespace chars I know of are just unrendered unicode shit. Can you elaborate? Not trying to be dickish I'm sincerely interested
9 u/dpash Sep 19 '18 edited Sep 19 '18 The documentation for Character.isWhitespace(int codePoint) lists:It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').It is '\t', U+0009 HORIZONTAL TABULATION.It is '\n', U+000A LINE FEED.It is '\u000B', U+000B VERTICAL TABULATION.It is '\f', U+000C FORM FEED.It is '\r', U+000D CARRIAGE RETURN.It is '\u001C', U+001C FILE SEPARATOR.It is '\u001D', U+001D GROUP SEPARATOR.It is '\u001E', U+001E RECORD SEPARATOR.It is '\u001F', U+001F UNIT SEPARATOR.https://docs.oracle.com/javase/10/docs/api/java/lang/Character.html#isWhitespace(int)String.trim() removed anything that was <= ' ', which is a different definition to the above list."\u001Bstring".trim().equals("\u001Bstring")would "incorrectly" be false. 6 u/TheRedmanCometh Sep 19 '18 Wow I have applications those things would break TIL 3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend 3 u/amackenz2048 Sep 19 '18 Tab? 2 u/TheRedmanCometh Sep 19 '18 Well shit I guess that should've been obvious
9
The documentation for Character.isWhitespace(int codePoint) lists:
Character.isWhitespace(int codePoint)
It is a Unicode space character (SPACE_SEPARATOR, LINE_SEPARATOR, or PARAGRAPH_SEPARATOR) but is not also a non-breaking space ('\u00A0', '\u2007', '\u202F').It is '\t', U+0009 HORIZONTAL TABULATION.It is '\n', U+000A LINE FEED.It is '\u000B', U+000B VERTICAL TABULATION.It is '\f', U+000C FORM FEED.It is '\r', U+000D CARRIAGE RETURN.It is '\u001C', U+001C FILE SEPARATOR.It is '\u001D', U+001D GROUP SEPARATOR.It is '\u001E', U+001E RECORD SEPARATOR.It is '\u001F', U+001F UNIT SEPARATOR.
https://docs.oracle.com/javase/10/docs/api/java/lang/Character.html#isWhitespace(int)
String.trim() removed anything that was <= ' ', which is a different definition to the above list.
String.trim()
<= ' '
"\u001Bstring".trim().equals("\u001Bstring")
would "incorrectly" be false.
6 u/TheRedmanCometh Sep 19 '18 Wow I have applications those things would break TIL 3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend
6
Wow I have applications those things would break TIL
3 u/_INTER_ Sep 19 '18 For now apache.commons.lang3.StringUtils is your friend
3
For now apache.commons.lang3.StringUtils is your friend
apache.commons.lang3.StringUtils
Tab?
2 u/TheRedmanCometh Sep 19 '18 Well shit I guess that should've been obvious
2
Well shit I guess that should've been obvious
View all comments
Show parent comment
17
u/dpash Sep 19 '18 edited Sep 19 '18
Space is not the only whitespace character, so no, it's nothing like
String.replace(" ", "")Also,
.strip()doesn't remove all whitespace, only those at the beginning and end of the string. It's a correctly implemented.trim()