?, /, =/ *, ", $," put these symbols into an array. and then check your source has the particular character or not using contains/indexOf method of String in a loop.
Please don't bother posting code that won't even compile.
Nick Rowe
Ranch Hand
Posts: 88
posted 10 years ago
Hi All, the code wasn't supposed to compile, it was simply meant to give an idea of what i am trying to achieve.
I have a document that I am trying to extract a list of variables from, these variables are stored in instances of a string i have called resourceline. However i only want to add the variable to the array if it does not contain any symbols and also if it does not already exist.
the resourceline value will be different in most instances so i cannot pinpoint if it does or does not contain any symbols.
All i am asking is how I should correctly write if my resourceline variable contains any symbols.
Normally I would say yes if the string was constant. However the string changes continuously so i cannot say something simple along the lines of something like.
But you're not looking for equals, you're looking for a contains, or a regex. So is there anything else in the string api that might work?
Nick Rowe
Ranch Hand
Posts: 88
posted 10 years ago
A regex solution would make things far more difficult as i am already using a regex to capture the string that I want to investigate.
The code will need to be used within my find method in the forms of an if statement using something that searches for a character(S) then dependant on if that character exists within the variable resource line at that time and if it already exists within the array, a series of events will follow.
So would instances of below work
boolean checkContains1=resourceline.contains("$");
boolean checkContains2=resourceline.contains("=");
boolean checkContains3=resourceline.contains(""");
boolean checkContains4=resourceline.contains(">");
boolean checkContains5=resourceline.contains(":");
Why don't you try them, and see if what you were expecting is output.
Hunter
"If the facts don't fit the theory, get new facts" --Albert Einstein
Nick Rowe
Ranch Hand
Posts: 88
posted 10 years ago
Ok so basically I've tried the code below and get one error from the compiler saying that != is an illegal start of an expression. This is on the
if (checkContains1 || checkContains2 || checkContains3|| checkContains4|| !=true) line
Again: even if you're posting pseudo-code, please check that it makes sense. It throws people off to have to understand whatever notation it is you're trying to use *and* solve the problem at the same time. We don't know if you believe what you're writing will work or not if it won't even compile.
Stick to posting actual code. Please.
Nick Rowe
Ranch Hand
Posts: 88
posted 10 years ago
This is probably a stupid question but im wondering if there is a specific way of calling back a method from another method. My program only has one class to Im not calling it from anywhere else.
I've tried
public static void main(String[] args);
main();
main(String[] args);
and the compiler isn't having any of it.
regards S
I'll post my code below
Look! It's Leonardo da Vinci! And he brought a tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop