AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

String-splitting trouble

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Aki Sus Laukkanen
Guest





PostPosted: Thu Jul 22, 2004 5:38 pm    Post subject: String-splitting trouble Reply with quote




Hello again :)

It's been a while since I've had a problem that I couldn't solve myself
-making progress?)

However, here's a tricky one:

I'm trying to parse a set of conditions from a String.
The conditions would be like

<variable number>=<value> OR <another variable number>=<another value>.

As a String it looks like this:

String condition = "31=0|31=9"

To process the OR in the condition, I'm trying to split the String in
two, like this:

String[]piecesOfCondition = condition.split("|");

However, instead of
[0]="31=0", [1]="31=9"

the resulting table looks like
[0]="", [1]="3", [2]="1", [3]="=", [4]="0", [5]="|", [6]="3", [7]="1",
[8]="=", [9]="9"

Anybody got any idea what I'm doing wrong here?

Thanks,
--
-Aki "Sus" Laukkanen


Back to top
Roedy Green
Guest





PostPosted: Thu Jul 22, 2004 5:49 pm    Post subject: Re: String-splitting trouble Reply with quote



On Thu, 22 Jul 2004 20:38:08 +0300, "Aki "Sus" Laukkanen"
<aki.laukkanenREMOVETHIS (AT) helsinki (DOT) fi> wrote or quoted :

Quote:
String[]piecesOfCondition = condition.split("|");

check out http://mindprod.com/jgloss/regex.html

Isn't | a magic char to Regex? Thus it needs quoting. But then the
char needs Java quoting.

so try

split( "\|" );

The other way to do this is with a parser. See
http://mindprod.com/jgloss/parser.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Back to top
Aki Sus Laukkanen
Guest





PostPosted: Thu Jul 22, 2004 5:59 pm    Post subject: Re: String-splitting trouble Reply with quote



Roedy Green wrote:

Quote:
String[]piecesOfCondition = condition.split("|");

check out http://mindprod.com/jgloss/regex.html

Isn't | a magic char to Regex? Thus it needs quoting. But then the
char needs Java quoting.

so try

split( "\|" );

Yup, that was the problem. After adding the backslashes it works OK.
Damn those "magic" characters... :|

Thanks a lot for the tip. :)

--
-Aki "Sus" Laukkanen


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.