Today I was trying to detect if a string contains a dot, but my code isn't working
String s = "test.test";
if(s.contains("\\.")) {
System.out.printLn("string contains dot");
}
Use the includes() method to check if a string contains a period, e.g. str. includes('. ') . The includes method will return true if the string contains a period, otherwise false will be returned.
The easiest way is to check with a . contains() statement. Note: . contains() works only for strings.
Answer: Use the PHP strpos() Function You can use the PHP strpos() function to check whether a string contains a specific word or not. The strpos() function returns the position of the first occurrence of a substring in a string. If the substring is not found it returns false .
The Java String contains() method is used to check whether the specific set of characters are part of the given string or not. It returns a boolean value true if the specified characters are substring of a given string and returns false otherwise. It can be directly used inside the if statement.
contains()
method of String class does not take regular expression as a parameter, it takes normal text.
String s = "test.test";
if(s.contains("."))
{
System.out.println("string contains dot");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With