Given a valid (IPv4) Internet Protocol address S, the task is to find the defanged version of that IP address.
Defanged Version of IP Address: is in which every period “.” is replaced by “[.]”.
Input: S = “18.104.22.168”
Input: S = “255.100.50.0”
Approach: The idea is to traverse the string and append every character of the string into the final answer string except when the current character is “.”, then append “[.]” into the final answer string.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Compare two Version numbers
- Compare Version Numbers with large inputs allowed
- How to validate an IP address using ReGex
- Program to validate an IP address
- How to validate MAC address using Regular Expression
- Python | Remove leading zeros from an IP address
- Perform range sum queries on string as per given condition
- Generate a String of having N*N distinct non-palindromic Substrings
- Lexicographically largest possible String after removal of K characters
- Maximum area of a Rectangle that can be circumscribed about a given Rectangle of size LxW
- Check if a given string is Pangram in Java
- C program to trim leading white spaces from String
- Generate all possible permutations of a Number divisible by N
- Construct an Array of Strings having Longest Common Prefix specified by the given Array
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.