File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Dumping A string value??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Dumping A string value???" Watch "Dumping A string value???" New topic
Author

Dumping A string value???

Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Hi all,

I have a program that captures a substring between two strings and returns the value instance to an arrayList, however if the value already exists or contains certain symbols I want my program to dump the string and look at the next line.

I have done this with a series of IF statements however, when my program is executed its still returning many string values that contain these character symbols.

I have tried leaving the loop blank thinking that maybe it will just abandon the string within the IF statement if the conditions aren't met. But the string values are still comming through. Another method I have tried is setting the variable value for resourceline to null. But that just causes compiler errors.

Please can someone help

p.s. Apologies if there are any formatting errors

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Your addition of "resourceline" to the array list is completely independent of whether or not "resourceline" contains any of the characters--it sounds like that's not what you want.
Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
Basically if there is a value within the resourceline I want it to first trim the value and then iterate through the statements. I am expecting the If statments to search the string to see if it contains any of the symbol characters. If a character is found within the string then set the string to null (i.e dump the entire string value) and do the same thing If the value already exists within the arrayList.

Otherwise if the resourceline value does not contain any conflicting irrelevant data only then add to the array.

So how is the array being populated with all the crap IF im only adding the value after iterating through the IF statements. It just doesn't make sense to me. Surely it would only add the value If the data was correct?

regards S
Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
I believe i just had a eureka moment.

I changed my code to the example shown below and it seems to have worked, i realise i missed the else if aswel




David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why set resourceline to null? You just set it again a statement later.
Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
I realise that there are two possibilities for this i.e. the method from the previous post and also the solution below.

I was just testing the first method at the time, and posted.
By the looks of it the only issue i have now is that the odd occurance of a single character has come through as a variable on the odd occasion.

So i need to find if the value is equal to one character and add that to the If or scenario.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I was actually just asking why you set resourceline to null, because you immediately set it again the next time through the "while" loop.
Nick Rowe
Ranch Hand

Joined: May 26, 2010
Posts: 88
I see what you mean now, i have removed it from the if statement.

regards S
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Dumping A string value???