Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to check that string contains two of the same characters?

Tags:

People also ask

How do you check if two characters in a string are the same?

To find whether a string has all the same characters. Traverse the whole string from index 1 and check whether that character matches the first character of the string or not. If yes, then match until string size. If no, then break the loop.

How do I check if two characters are the same in Python?

Python strings equality can be checked using == operator or __eq__() function. Python strings are case sensitive, so these equality check methods are also case sensitive.

How do I get two characters from a string?

String rmtdir = Filename. substring(Filename. length() - 12, Filename. length() - 14);

How do I check if a string contains one character?

You can use string. indexOf('a') . If the char a is present in string : it returns the the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.


Lets say I have:

str = "Hello! My name is Barney!"

Is there a one or two line method to check if this string contains two !?