Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dumping A string value???

 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why set resourceline to null? You just set it again a statement later.
 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see what you mean now, i have removed it from the if statement.

regards S
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic