Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7364
| Date | 2011-08-24 22:49 -0700 |
|---|---|
| From | Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: How to join a range of array string slots with blank delimiters? Almost opposite of string.split()? |
| References | <4e55dd30$0$7613$9b4e6d93@newsspool1.arcor-online.net> |
| Message-ID | <LuqdnQ3pFovJf8jTnZ2dnUVZ_uOdnZ2d@posted.palinacquisition> (permalink) |
On 8/24/11 10:27 PM, Gunter Hansen wrote:
> Assume I split a text line with a command like:
>
> String[] part = line.split("\\s+");
>
> Ok, fine, but how is the opposite command?
> Keep in mind that the delimiter between the joined slots of the target string should be one blank.
>
> Moreover: Can I join e.g. only slots [3],...,[MAX]?
>
> So I need a command similar to:
>
> String joined = part[3,MAX].join(' ');
>
> How ca I achieve this?
>
> If this is not possible directly then maxbe with a work around?
I am surprised the feature doesn't exist in the JDK; in .NET there's a
String.Join() method that does exactly what you're asking about. But
AFAIK, it doesn't.
That said, it's trivial to write one yourself, or you could use the
Apache StringUtils library (as this top-three Bing hit mentions in two
different replies:
http://stackoverflow.com/questions/187676/string-operations-in-java
…funny what a web search will turn up, if you just do the search).
And I have to admit, I think Java's take on the "split" function is
pretty cool, what with regex support and all (which .NET doesn't
provide, not as a String.Split() feature anyway). So IMHO Java wins
this particular feature comparison. :)
Pete
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
How to join a range of array string slots with blank delimiters? Almost opposite of string.split()? GHansen@hotmail.com (Gunter Hansen) - 2011-08-25 05:27 +0000
Re: How to join a range of array string slots with blank delimiters? Almost opposite of string.split()? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-24 22:49 -0700
回复:Re: How to join a range of array string slots with blank delimiters? Almost opposite of string.split()? Yuxuan Wang <crnlmcn@gmail.com> - 2011-08-24 23:42 -0700
Re: How to join a range of array string slots with blank delimiters? Almost opposite of string.split()? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-25 22:31 -0400
Re: How to join a range of array string slots with blank delimiters? Almost opposite of string.split()? Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-25 20:15 -0700
Re: How to join a range of array string slots with blank delimiters? Almost opposite of string.split()? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-25 13:05 -0700
Re: How to join a range of array string slots with blank delimiters? Almost opposite of string.split()? Roedy Green <see_website@mindprod.com.invalid> - 2011-08-31 23:41 -0700
Re: How to join a range of array string slots with blank delimiters? Almost opposite of string.split()? Arne Vajhøj <arne@vajhoej.dk> - 2011-08-25 22:28 -0400
csiph-web