class TesteStrings {
public static void main
(String[] args
) { System.
out.
println("Com ltrim: (" + ltrim
(x
) + ")"); System.
out.
println("Com rtrim: (" + rtrim
(x
) + ")"); }
char[] val = toTrim.toCharArray();
int len = val.length;
while (len > 0 && val[len - 1] <= ' ') {
len--;
}
return len < val.length ? toTrim.substring(0, len) : toTrim;
}
int st = 0;
char[] val = toTrim.toCharArray();
int len = val.length;
while (st < len && val[st] <= ' ') {
st++;
}
return st > 0 ? toTrim.substring(st, len) : toTrim;
}
}
Y2xhc3MgVGVzdGVTdHJpbmdzIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBTdHJpbmcgeCA9ICIgICAgICAgUEFSQSBEQVIgVFJJTSAgICAgICAiOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiQ29tIGx0cmltOiAoIiArIGx0cmltKHgpICsgIikiKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkNvbSBydHJpbTogKCIgKyBydHJpbSh4KSArICIpIik7CiAgICB9CgogICAgcHVibGljIHN0YXRpYyBTdHJpbmcgcnRyaW0oU3RyaW5nIHRvVHJpbSkgewogICAgICAgIGNoYXJbXSB2YWwgPSB0b1RyaW0udG9DaGFyQXJyYXkoKTsKICAgICAgICBpbnQgbGVuID0gdmFsLmxlbmd0aDsKCiAgICAgICAgd2hpbGUgKGxlbiA+IDAgJiYgdmFsW2xlbiAtIDFdIDw9ICcgJykgewogICAgICAgICAgICBsZW4tLTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGxlbiA8IHZhbC5sZW5ndGggPyB0b1RyaW0uc3Vic3RyaW5nKDAsIGxlbikgOiB0b1RyaW07CiAgICB9CgogICAgcHVibGljIHN0YXRpYyBTdHJpbmcgbHRyaW0oU3RyaW5nIHRvVHJpbSkgewogICAgICAgIGludCBzdCA9IDA7CiAgICAgICAgY2hhcltdIHZhbCA9IHRvVHJpbS50b0NoYXJBcnJheSgpOwogICAgICAgIGludCBsZW4gPSB2YWwubGVuZ3RoOwoKICAgICAgICB3aGlsZSAoc3QgPCBsZW4gJiYgdmFsW3N0XSA8PSAnICcpIHsKICAgICAgICAgICAgc3QrKzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHN0ID4gMCA/IHRvVHJpbS5zdWJzdHJpbmcoc3QsIGxlbikgOiB0b1RyaW07CiAgICB9Cn0=