aspose file tools
The moose likes Java in General and the fly likes Finding exact element in String Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Finding exact element in String" Watch "Finding exact element in String" New topic
Author

Finding exact element in String

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

Hello,

I have a string strCurrentTableRow which contains xxxxxxxxxCD01xxCD01(A)xxxxxxxxAB01xxxxxxxxxxxAB01(A)xxxxxxxxx where x is any character and the position of AB01 can change anywhere.

Now, I'm using a variable strCurrentRequiredJf which will have either AB01 or AB01(A), which will be dynamic, meaning it can be CD01 or CD01(A) as well based on the stuff selected by the end user.

I have an IF condition in a part of the code which contains many WHILE loops,


in this case, since 'contains' returns true both for AB01 & AB01(A), the code in the loop will execute twice whereas it should have happened just once.

In short, how to find the exact substring in a string.
contains() doesn't work, so does indexOf().

So how to rectify this issue.

Please advise.


Thanks,
Pramod
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 316

I changed in the indexOf condition and found the result.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Finding exact element in String
 
Similar Threads
Finding exact match of one string in another..
Write code at run time
String constructor
Struts2: which result type to use
Problem with strings with duplicate space characters