Given two strings that can contain lower and uppercase alphabets, numbers and special characters like dots, blank spaces, commas, etc. Compare both strings considering only alphanumeric characters([a-b], [A-B] and [0-9]) if they are equal or not. For example, strings “Ram, Shyam” and “Ram-Shyam” both are the same and also “/.’;” and “@# >” are same.
Input: str1 = "Ram, Shyam", str2 = " Ram - Shyam." Output: Equal Explanation: if we ignore all characters except alphanumeric characters then strings will be, str1 = "RamShyam" and str2 = "RamShyam". Therefore both strings are equal. Input : str1 = "aaa123", str2 = "@aaa-12-3" Output : Equal Input : str1 = "abc123", str2 = "123abc" Output : Unequal Explanation: In this, str1 = "abc123" and str2 = "123abc". Therefore both strings are not equal.
Since we have to compare only alphanumeric characters therefore whenever any other character is found simply ignore it by increasing iterator pointer. For doing it simply take two integer variables i and j and initialize them by 0. Now run a loop to compare each and every character of both strings. Compare one by one if the character is alphanumeric otherwise increase the value of i or j by one.
Below is the implementation of the above approach:
- Remove characters from the first string which are present in the second string
- A Program to check if strings are rotations of each other or not
- Print list items containing all characters of a given word
- Find the smallest window in a string containing all characters of another string
- Length of the longest substring without repeating characters
- Check whether two strings are anagram of each other
- Print all permutations with repetition of characters
- Print all interleavings of given two strings
- Interleaving of two given strings with no common characters
- String matching where one string contains wildcard characters
- Find if a string is interleaved of two other strings | DP-33
- Find the first non-repeating character from a stream of characters
- Rearrange a string so that all same characters become d distance away
- Given a sorted dictionary of an alien language, find order of characters
- Find if an array of strings can be chained to form a circle | Set 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Rajput-Ji