This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

returning text from a string object  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Hope someone can help me.

I run a bash command and save the output as a string object
String str1 = "" +getLastOutput();

str1 would look like this: abcd efgh lkmn xsds

In this string ( str1) i need to check three separate words are there.

If i have an if statement with str1.contains("xyz") && str1.contains("lkmn") &&str1.contains("zzzzzzzzzzzz")

How can i get the one that is not there returned to the screen? so i can use elsewhere??

thanks for your help
 
Sheriff
Posts: 4748
133
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

"The one that is not there..." That word(s)? The condition(s) that don't match?

Either way you probably want to break that if statement into separate if .. else if statements.

 
T No
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your kind reply

I was looking at if and if else statements and i felt it was not going to do what i needed. if the string contains the characters - i dont need to do anything.

I just want the piece of text that is not in the string st1 so in this case ("zzzzzz") to be returned to me.

If i used && - how can i get the false && out to the screen? so in this case ("zzzzz") be shown on screen?


Thank you
 
Knute Snortum
Sheriff
Posts: 4748
133
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!