简体   繁体   中英

Java String trim has no effect

Java String trim is not removing a whitespace character for me.

String rank = (some method);
System.out.println("(" + rank + ")");

The output is (1 ) . Notice the space to the right of the 1.

I have to remove the trailing space from the string rank but neither rank.trim() nor rank.replace(" ","") removes it.

The string rank just remains the same either way.

Edit: Full Code: :

Document doc = Jsoup.connect("http://www.4icu.org/ca/").timeout(1000000).get();
Element table = doc.select("table").get(7);
Elements rows = table.select("tr");
for (Element row: rows) {
  String rank = row.select("span").first().text().trim();
  System.out.println("("+rank+")");
}

Why can't I remove that space?

Java String trim is not removing a whitespace character for me.

String rank = (some method);
System.out.println("(" + rank + ")");

The output is (1 ) . Notice the space to the right of the 1.

I have to remove the trailing space from the string rank but neither rank.trim() nor rank.replace(" ","") removes it.

The string rank just remains the same either way.

Edit: Full Code: :

Document doc = Jsoup.connect("http://www.4icu.org/ca/").timeout(1000000).get();
Element table = doc.select("table").get(7);
Elements rows = table.select("tr");
for (Element row: rows) {
  String rank = row.select("span").first().text().trim();
  System.out.println("("+rank+")");
}

Why can't I remove that space?

Java String trim is not removing a whitespace character for me.

String rank = (some method);
System.out.println("(" + rank + ")");

The output is (1 ) . Notice the space to the right of the 1.

I have to remove the trailing space from the string rank but neither rank.trim() nor rank.replace(" ","") removes it.

The string rank just remains the same either way.

Edit: Full Code: :

Document doc = Jsoup.connect("http://www.4icu.org/ca/").timeout(1000000).get();
Element table = doc.select("table").get(7);
Elements rows = table.select("tr");
for (Element row: rows) {
  String rank = row.select("span").first().text().trim();
  System.out.println("("+rank+")");
}

Why can't I remove that space?

Java String trim is not removing a whitespace character for me.

String rank = (some method);
System.out.println("(" + rank + ")");

The output is (1 ) . Notice the space to the right of the 1.

I have to remove the trailing space from the string rank but neither rank.trim() nor rank.replace(" ","") removes it.

The string rank just remains the same either way.

Edit: Full Code: :

Document doc = Jsoup.connect("http://www.4icu.org/ca/").timeout(1000000).get();
Element table = doc.select("table").get(7);
Elements rows = table.select("tr");
for (Element row: rows) {
  String rank = row.select("span").first().text().trim();
  System.out.println("("+rank+")");
}

Why can't I remove that space?

Java String trim is not removing a whitespace character for me.

String rank = (some method);
System.out.println("(" + rank + ")");

The output is (1 ) . Notice the space to the right of the 1.

I have to remove the trailing space from the string rank but neither rank.trim() nor rank.replace(" ","") removes it.

The string rank just remains the same either way.

Edit: Full Code: :

Document doc = Jsoup.connect("http://www.4icu.org/ca/").timeout(1000000).get();
Element table = doc.select("table").get(7);
Elements rows = table.select("tr");
for (Element row: rows) {
  String rank = row.select("span").first().text().trim();
  System.out.println("("+rank+")");
}

Why can't I remove that space?

Java String trim is not removing a whitespace character for me.

String rank = (some method);
System.out.println("(" + rank + ")");

The output is (1 ) . Notice the space to the right of the 1.

I have to remove the trailing space from the string rank but neither rank.trim() nor rank.replace(" ","") removes it.

The string rank just remains the same either way.

Edit: Full Code: :

Document doc = Jsoup.connect("http://www.4icu.org/ca/").timeout(1000000).get();
Element table = doc.select("table").get(7);
Elements rows = table.select("tr");
for (Element row: rows) {
  String rank = row.select("span").first().text().trim();
  System.out.println("("+rank+")");
}

Why can't I remove that space?

Java String trim is not removing a whitespace character for me.

String rank = (some method);
System.out.println("(" + rank + ")");

The output is (1 ) . Notice the space to the right of the 1.

I have to remove the trailing space from the string rank but neither rank.trim() nor rank.replace(" ","") removes it.

The string rank just remains the same either way.

Edit: Full Code: :

Document doc = Jsoup.connect("http://www.4icu.org/ca/").timeout(1000000).get();
Element table = doc.select("table").get(7);
Elements rows = table.select("tr");
for (Element row: rows) {
  String rank = row.select("span").first().text().trim();
  System.out.println("("+rank+")");
}

Why can't I remove that space?

Java String trim is not removing a whitespace character for me.

String rank = (some method);
System.out.println("(" + rank + ")");

The output is (1 ) . Notice the space to the right of the 1.

I have to remove the trailing space from the string rank but neither rank.trim() nor rank.replace(" ","") removes it.

The string rank just remains the same either way.

Edit: Full Code: :

Document doc = Jsoup.connect("http://www.4icu.org/ca/").timeout(1000000).get();
Element table = doc.select("table").get(7);
Elements rows = table.select("tr");
for (Element row: rows) {
  String rank = row.select("span").first().text().trim();
  System.out.println("("+rank+")");
}

Why can't I remove that space?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM