Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 21157 invoked from network); 15 Apr 2009 14:32:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Apr 2009 14:32:38 -0000 Received: (qmail 53046 invoked by uid 500); 15 Apr 2009 14:32:34 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 52958 invoked by uid 500); 15 Apr 2009 14:32:34 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 52928 invoked by uid 99); 15 Apr 2009 14:32:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Apr 2009 14:32:34 +0000 X-ASF-Spam-Status: No, hits=2.8 required=10.0 tests=SPF_PASS,WEIRD_QUOTING X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of sebbaz@gmail.com designates 72.14.220.157 as permitted sender) Received: from [72.14.220.157] (HELO fg-out-1718.google.com) (72.14.220.157) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Apr 2009 14:32:27 +0000 Received: by fg-out-1718.google.com with SMTP id l27so613382fgb.1 for ; Wed, 15 Apr 2009 07:32:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=wN9q+aQOZwuqziM9UV+8TPHTqu4BeKg6IwPvbnfr4b0=; b=s4mThHrz7MUZOxT404CPZjXYyXtBO4GEJrTCrtovvzwBvFyiSlZy/Cwn7Hh0hxiawY nMTo4yFln/0ghcBeF7L/Dsg2v3Xh8Ux4YY7zYfK2SlEEajXdRzcNI6+33cB6MsVKkumu E7wmJDm1bisdelYsDY+mJbnJpIfMJtAPeSRqE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=CTfkdeT9dKU667nECuWNkqdAAy3tKpPoBfqoY1HvokC6siAsuvec6hV3v+rwbPvfdM sGJH1LXawfFsECJBmaV6+cpP5FVTkQ7zvkCKjcH9GozrsbjTlOKYCQhZVscEcGGLCAIZ R09yRVQRa6AbC7WTc+VUvIwWwpBAqzOy92gUY= MIME-Version: 1.0 Received: by 10.239.169.14 with SMTP id m14mr12385hbe.1.1239805925871; Wed, 15 Apr 2009 07:32:05 -0700 (PDT) In-Reply-To: <269a5c30904150539rc3bc48fw364252b8bf7d9996@mail.gmail.com> References: <269a5c30904150539rc3bc48fw364252b8bf7d9996@mail.gmail.com> Date: Wed, 15 Apr 2009 15:32:05 +0100 Message-ID: <25aac9fc0904150732q2ba4726fo3dda8ba35a2f9ce5@mail.gmail.com> Subject: Re: StrTokenizer not handling quotes correctly? From: sebb To: Commons Users List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On 15/04/2009, Jacek Furmankiewicz wrote: > I am trying to use StrTokenizer for some parsing and I am probably not using > it correctly. > > Let's say I have this string: > > 11"a,b"11,22"c,d"22" > > I would like to split it by the comma ",", but ignoring any commas embedded > in quotes. I try this: > > String test = "11\"a,b\"11,22\"c,d\"22"; > StrTokenizer str = new StrTokenizer(test,',','"'); > String[] tokens = str.getTokenArray(); > > for(String t: tokens) { > System.out.println(t); > } > > and expect to have two strings print out: > > 11"a,b"11 > 22"c,d"22 > > but instead I get 4 : > > 11"a > b"11 > 22"c > d"22 > > It seems the tokenizer is splitting on the comma, even if it is embedded in > quotes. Quotes are only allowed in quoted strings. From the Javadoc: "Each token may be surrounded by quotes. The quote matcher specifies the quote character(s). A quote may be escaped within a quoted section by duplicating itself. " > I tried different options on the StrTokenizer, but not been able to get it > to work correctly. > > Any idea as to what am I doing wrong? Using latest version 2.4. The input needs to look like this: "11""a,b""11","22""c,d""22"" > Thanks, Jacek > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org