-1

very new to java, but I can't seem to find how to do this in java..

var1 = "testing101"
if("101" in testing) balala

How do I do in, in java?

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;




public class Main {
    public static void buttonPressed(String[] args) {

        WebDriver driver = new ChromeDriver();
        driver.get("http://www.csgodouble.com/index.php");
        WebElement rollingTimer = driver.findElement(By.xpath("//*[@id=\"banner\"]"));
        if(rollingTimer :: "Rolling in 41")

    }
}

this is how I thought it was done..

  • `if(var1.contains("101"))` – Matthew Wright Mar 23 '16 at 22:43
  • 1
    Possible duplicate of [In Java, how do I check if a string contains a substring (ignoring case)?](http://stackoverflow.com/questions/2275004/in-java-how-do-i-check-if-a-string-contains-a-substring-ignoring-case) – maximede Mar 23 '16 at 22:45

4 Answers4

4

If you trying to see if a string contains a sub string:

String var1 = "testing101"
if(var1.contains("101"))
Sam Orozco
  • 1,120
  • 11
  • 22
0

I think you may want to use the contains method of String class.

Cajova_Houba
  • 44
  • 1
  • 9
0

For a String in Java to see if a String is contained in another one do:

String str1 = "testing 1";
if(str1.contains("testing"))
{
     //Add your code here
 }
mantlabs
  • 352
  • 2
  • 6
0

Likewise, you can compare string for equallity check,

    if("Rolling in 41".equals(rollingTimer )){ // compare with case-sensitive

    }

    // OR this way also

if("Rolling in 41".equalsIgnoreCase(rollingTimer )){ // compare without case-sensitive

    }
Vishal Gajera
  • 3,798
  • 3
  • 23
  • 49