This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

matcher and dollar sign

 
lydie prevost
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
In order to know if a record is already in the database, I am using a pattern and matcher to compare each record :


This works welll for evey thing except when I am comparing the hourly charge for each contractor because it contains a currency symbol which could be a dollar sign and $ is a specila character for matcher.
I don't know how to replace the "$" by "\$" if it is present . It could also be another currency symbol, so I don't always know that a $ is present , I first have to look for it then replace it.
Can somebody help me with that
Thanks
Lydie
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you ask such general Java questions in one of the Java in General forums? I'm sure you will get a response quite quickly.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lydie,

The easiest answer I know of is to disallow searching in the hourly charge field . After all, I don't think that this is one of the fields that you must search on.

Alternatively let the $ sign go through, and just inform the user that the $ and ^ have special meanings that they are allowed to use, but if they want to search for something containing the $ sign then they should escape it (change the problem into a 'feature and benefit' for them ).

Another alternative would be to use String's replace method to change the $ to a \$ (it is the only currency symbol you need to worry about in regular expressions). While this would mean that you would not be able to use the $ sign to match the end of a line, you are dealing with a database here - not a text document - so this might be acceptable. This would be a design choice and should be documented as such.

Originally posted by Barry Gaunt:
Why don't you ask such general Java questions in one of the Java in General forums? I'm sure you will get a response quite quickly.


Let me know if you would like this moved to JiG Intermediate, and I will move it.

Regards, Andrew
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lydie, on re-reading my previous post, I realised that it could be misinterpreted.
I did not mean that such a topic is unwelcome, I meant to point out that for technical issues such as regex expert help is available in those forums if you need it.
As Andrew has pointed out there are also ways to work around the problem in the context of SCJD.

-Barry
 
lydie prevost
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It tookk me a while, but I finally found how to do it :
I can then matche a string even with the dollar sign
Lydie
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have provided list of values (pre-decided room rates for URLBird). I will mention this in choices.txt and also provide explanation that for future enhancement application can provide rate search with two textfields, where client can say I want room between 50 to 100 etc...

But for current assignment scope I will only display pre-decided list of values of rates per night. User can also search by hotel name, location and smoking (yes/no). I think this will cover most of the search requirement for assignment scope.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic