 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Aki Sus Laukkanen Guest
|
Posted: Thu Jul 22, 2004 5:38 pm Post subject: String-splitting trouble |
|
|
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
|
Posted: Thu Jul 22, 2004 5:49 pm Post subject: Re: String-splitting trouble |
|
|
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
|
Posted: Thu Jul 22, 2004 5:59 pm Post subject: Re: String-splitting trouble |
|
|
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 |
|
 |
|
|
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
|
|