Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if a string contains a dot

Tags:

java

string

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");
 }
like image 926
Robin De Baets Avatar asked Aug 23 '15 14:08

Robin De Baets


People also ask

How do you check if a string contains a fullstop?

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.

How do I check if a string contains a dot in Python?

The easiest way is to check with a . contains() statement. Note: . contains() works only for strings.

How do you check if a string contains a phrase?

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 .

How do you check if a string contains a character?

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.


1 Answers

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");
}
like image 155
HaveNoDisplayName Avatar answered Sep 19 '22 12:09

HaveNoDisplayName