Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #25356

Re: how to trim() a String only at the right side?

From Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at>
Newsgroups comp.lang.java.programmer
Subject Re: how to trim() a String only at the right side?
Date 2013-09-26 16:56 +0000
Organization A noiseless patient Spider
Message-ID <slrnl48pq1.mol.avl@gamma.logic.tuwien.ac.at> (permalink)
References <slrnl45qr1.mol.avl@gamma.logic.tuwien.ac.at>

Show all headers | View raw


A summary of the answers so far is:
-) use regex:   A while ago, I liked REs, but with many tools 
      using different dialects of it, my enthusiasm has declined.
      Thanks, anyway, for suggesting it.

-) a recursive function:  lol ;-)

-) prepend an "x", then trim() it, then remove the "x": 
      A nice&compact one, and I'm not yet in the phase for
      performance-considerations, so I might actually start
      out using it.  That it eats not only blanks, but also
      control chars will not be a real problem, until I get
      to rewrite it. The strings I'm going to deal with are
      unlikely to contain tabs or newlines, so if this ever
      bites someone, that might be many years from now and
      give a job to some future programmer to fix ;)

-) Use Apache Utils' StringUtils class: good to know, but
      at this time it would be the first/only thing from that
      library, so I'm reluctant to include a 3rd party library
      for some code of maybe 3-4 lines (if done with a loop).

Thanks to *all* who answered.  I'll now reread them all, and 
eventually make specific followups to some.

Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> wrote:
> I'd need to trim only *trailing* whitespace off a String (or StringBuilder)
> while preserving leading white space. Furthermore (unlike trim()), I'd only
> strip exact \u0020 chars, no other control chars.
> ...

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

how to trim() a String only at the right side? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-25 13:55 +0000
  Re: how to trim() a String only at the right side? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-09-25 10:25 -0400
  Re: how to trim() a String only at the right side? "John B. Matthews" <nospam@nospam.invalid> - 2013-09-25 12:55 -0400
  Re: how to trim() a String only at the right side? Jim Janney <jjanney@shell.xmission.com> - 2013-09-25 13:05 -0600
  Re: how to trim() a String only at the right side? Silvio <silvio@internet.com> - 2013-09-25 21:46 +0200
  Re: how to trim() a String only at the right side? markspace <markspace@nospam.nospam> - 2013-09-25 13:31 -0700
    Re: how to trim() a String only at the right side? markspace <markspace@nospam.nospam> - 2013-09-25 13:41 -0700
      Re: how to trim() a String only at the right side? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-26 17:11 +0000
    Re: how to trim() a String only at the right side? Silvio <silvio@internet.com> - 2013-09-26 12:14 +0200
    Re: how to trim() a String only at the right side? Jim Janney <jjanney@shell.xmission.com> - 2013-09-26 09:44 -0600
      Re: how to trim() a String only at the right side? Arne Vajhøj <arne@vajhoej.dk> - 2013-09-26 13:01 -0400
  Re: how to trim() a String only at the right side? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-09-26 12:21 +0100
    Re: how to trim() a String only at the right side? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-09-26 17:40 +0100
  Re: how to trim() a String only at the right side? Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-26 16:56 +0000

csiph-web