Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #15954
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Knute Johnson <nospam@rabbitbrush.frazmtn.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: need regular expression to replace part of result based on a search pattern |
| Date | Wed, 11 Jul 2012 15:40:00 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 43 |
| Message-ID | <jtkvc3$vu6$1@dont-email.me> (permalink) |
| References | <6aefda61-b66a-4e8f-8634-ef6a95f79c4d@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 11 Jul 2012 22:40:03 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="eb9f7a5c1f0f4ba5a3281982f4e5ff5e"; logging-data="32710"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+IKymyFqRA75yDrMUJc6Ld" |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 |
| In-Reply-To | <6aefda61-b66a-4e8f-8634-ef6a95f79c4d@googlegroups.com> |
| Cancel-Lock | sha1:a5Ni5UKSgkeT/vwu2AYJ7pmsvBk= |
| Xref | csiph.com comp.lang.java.programmer:15954 |
Show key headers only | View raw
On 7/11/2012 10:35 AM, Jimmy wrote:
> Have been having hard time to come up with the regular expression to replace the following..
>
> 1,"blaha",NULL,'N','Y','N','N',NULL
> 2,"blahb",NULL,'Y','Y','Y','N',NULL
> 3,"blahc",NULL,'N','N','N','N',NULL
> ^
>
> With all contents in column #6 (first column is column #1) to 'Y'?
>
> i.e. result
>
> 1,"blaha",NULL,'N','Y','Y','N',NULL
> 2,"blahb",NULL,'Y','Y','Y','N',NULL
> 3,"blahc",NULL,'N','N','Y','N',NULL
> ^
>
> Thanks,
> Jimmy
>
public class test {
public static void main(String[] args) {
String str = "3,\"blaha\",NULL,'N','N','N','N',NULL";
System.out.println(str);
String[] arr = str.split(",");
if (arr[5].equals("'N'"))
arr[5] = "'Y'";
StringBuilder sb = new StringBuilder();
for (int i=0; i<arr.length; i++) {
sb.append(arr[i]);
if (i != arr.length - 1)
sb.append(",");
}
System.out.println(sb);
}
}
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
need regular expression to replace part of result based on a search pattern Jimmy <jimmy_please@yahoo.com> - 2012-07-11 10:35 -0700
Re: need regular expression to replace part of result based on a search pattern Roedy Green <see_website@mindprod.com.invalid> - 2012-07-11 15:24 -0700
Re: need regular expression to replace part of result based on a search pattern Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2012-07-11 15:40 -0700
Re: need regular expression to replace part of result based on a search pattern Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2012-07-12 00:56 +0200
Re: need regular expression to replace part of result based on a search pattern Roedy Green <see_website@mindprod.com.invalid> - 2012-07-11 21:21 -0700
Re: need regular expression to replace part of result based on a search pattern Jimmy <jimmy_please@yahoo.com> - 2012-07-12 07:28 -0700
Re: need regular expression to replace part of result based on a search pattern Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-12 11:24 -0400
Re: need regular expression to replace part of result based on a search pattern Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-07-12 11:42 -0400
Re: need regular expression to replace part of result based on a search pattern Arne Vajhøj <arne@vajhoej.dk> - 2012-07-23 22:55 -0400
Re: need regular expression to replace part of result based on a search pattern Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-07-12 09:42 -0500
Re: need regular expression to replace part of result based on a search pattern Gene Wirchenko <genew@ocis.net> - 2012-07-12 09:18 -0700
Re: need regular expression to replace part of result based on a search pattern glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2012-07-12 18:34 +0000
Re: need regular expression to replace part of result based on a search pattern Arne Vajhøj <arne@vajhoej.dk> - 2012-07-23 22:53 -0400
Re: need regular expression to replace part of result based on a search pattern Arne Vajhøj <arne@vajhoej.dk> - 2012-07-23 22:48 -0400
Re: need regular expression to replace part of result based on a search pattern Arne Vajhøj <arne@vajhoej.dk> - 2012-07-25 17:37 -0400
csiph-web