Forums Register Login

Why does this throw an exception?

+Pie Number of slices to send: Send
Here's some code:



And here's what it throws:



The question is: Why the hell does it throw it?
+Pie Number of slices to send: Send
That's a really good question. It definitely doesn't have to do with length.

Edit: It has to do with having a back slash at the end of the string. Remove it and you will see what I mean.
[ July 01, 2004: Message edited by: Darin Niard ]
+Pie Number of slices to send: Send
I'm not sure what's going on, but note that the documentation for replaceAll() tells us (if you follow the link to the Matcher class' method) that the replacement string is not treated literally, and backslashes have special meaning as escape characters - which is probalby not what you want. So you probably need to again double (that is, quadruple) each \ in your preplacement string literal, to get:

String APP_ROOT = "C:\\\\Documents and Settings\\\\SysOp\\\\My Documents\\\\AB LOGIC\\\\Eclipse Workspace\\\\abLogic\\\\web\\\\";

Strange, I know, but it should work. I bet it was the final \\ in the original string that caused the problem - the compiler translated that to a single \, and the regex parser saw that single \ and figured it was an escape for the following character. Except there was no following character, so it got confused.
+Pie Number of slices to send: Send
Notice that the same is true for '$'. That's why I have written a method for escaping replace values, which goes something like (IIRC - the following is from memory, and therefore untested):

+Pie Number of slices to send: Send
Please note: by writing the code like that, you are possibly breaking portability. For HTML strings, instead of escaping double quotes, you may use single quotes.
Everyone is a villain in someone else's story. Especially this devious tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2167 times.
Similar Threads
file reading in applet
how to "clear" jTable
xml validator problem
Do I need to reinstall Java?
Detecting a String that represents a number
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:41:58.