• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

If String Contains (symbols) then call main method

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok so basically I have an output from a file that needs shortening down and specifying as there is too much irrelevant data.

To do this I've done a bit of research and have come out with something along the following lines.

Please can someone help

kind regards S

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
?, /, =/ *, ", $," 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't bother posting code that won't even compile.
 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

regards S
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Rowe wrote:
All i am asking is how I should correctly write if my resourceline variable contains any symbols.



What you are asking for, is pretty straightforward. Why not take an attempt at it first?

Henry
 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



regards Nick
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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(":");


 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you try them, and see if what you were expecting is output.

Hunter
 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This:


Needs to look like this in Java:


You have to specify a value for each part of your condition.

Hunter
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use != true, use !:
This is identical to the following (De Morgan):
 
Nick Rowe
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so could i also try if

if (true(checkContains1 || checkContains2 || checkContains3 || checkContains4)) ???
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Rowe wrote:so could i also try if

if (true(checkContains1 || checkContains2 || checkContains3 || checkContains4)) ???



Just leaving the ! off would be checking if they were true.

Check True:


Check False:


Hunter
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
something wrong with the logic...


first "if" checks if resourceline != null, and then, if its null, you are adding it to the array list???
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Rowe wrote:A regex solution would make things far more difficult [...]


Not really.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic