Article View: pl.comp.lang.java
Article #153608Re: Split delimiter
From: mmarczyk2
Date: Thu, 04 Oct 2012 19:17
Date: Thu, 04 Oct 2012 19:17
49 lines
2292 bytes
2292 bytes
On Thursday, October 4, 2012 3:43:58 PM UTC+2, MarekF wrote:
> Witam
>
> Chce rozbic stringa do tablicy. W tablicy ma byc tylko to w nawiasach i
>
> jest, tylko czy mozna tak skonstruowac delimitera, zebo to zrobil od razu a
>
> nie w 3 splitach
>
> Dzialajacy kod:
>
> String produkt = "Produkt=new produkty(Produkt,0.8,0.2,11.8,41, 7 ,1)";
>
> //String delimiter = "[(]";
>
> String[] myString = produkt.split("[(]");
>
> System.out.println(myString[1]);
>
> //wynik Produkt,0.8,0.2,11.8,41, 7 ,1)
>
> String temp = myString[1];
>
> String[] temp1= temp.split("[)]");
>
> System.out.println(temp1[0]);
>
> //Wynik Produkt,0.8,0.2,11.8,41, 7 ,1
>
> String temp2 = temp1[0];
>
> String[] temp3 = temp2.split("[,]");
>
> System.out.println(temp3[0]);
>
> //wynik Produkt
>
> Pozdrawiam
>
> MarekF
Wykorzystaj wyrażenia regularne, na przykład tak:
String produkt = "Produkt=new produkty(Produkt,0.8,0.2,11.8,41, 7 ,1)";
System.out.println(produkt.replaceAll(".*\\(", "").replaceAll(",.*", ""));
Albo przy uzyciu Named Groups (więcej w tym wątku http://stackoverflow.com/questions/415580/regex-named-groups-in-java)
Marcin
Technical Details
Message-ID:
<33cda62d-66ce-4786-a067-fbd58da7ac79@googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!news.cyf-kr.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!l8no24891625qao.0!news-out.google.com!e10ni165558057qan.0!nntp.google.com!l8no25406804qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mailReferences:
<506d927e$0$1308$65785112@news.neostrada.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!news.cyf-kr.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!l8no24891625qao.0!news-out.google.com!e10ni165558057qan.0!nntp.google.com!l8no25406804qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: pl.comp.lang.java Date: Thu, 4 Oct 2012 12:17:48 -0700 (PDT) In-Reply-To: <506d927e$0$1308$65785112@news.neostrada.pl> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=91.222.140.35; posting-account=p2LEGQoAAAC0Ng2DZQs_G2xFh7n_aOIO NNTP-Posting-Host: 91.222.140.35 References: <506d927e$0$1308$65785112@news.neostrada.pl> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <33cda62d-66ce-4786-a067-fbd58da7ac79@googlegroups.com> Subject: Re: Split delimiter From: mmarczyk2@gmail.com Injection-Date: Thu, 04 Oct 2012 19:17:48 +0000 Lines: 52 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit