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


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

Re: How to join a range of array string slots with blank delimiters? Almost opposite of string.split()?

Date 2011-08-25 22:28 -0400
From Arne Vajhøj <arne@vajhoej.dk>
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 <4e5704be$0$310$14726298@news.sunsite.dk> (permalink)
Organization SunSITE.dk - Supporting Open source

Show all headers | View raw


On 8/25/2011 1:27 AM, 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.

You can always use a StringBuilder and a loop.

If you like weird one liners try:

line = Arrays.toString(part).replaceAll("[\\[\\],]", "");

> 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?

StringBuilder and a loop.

Arne

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Find similar


Thread

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