Tag Archives: String

Python Regex Replace Pattern in a string using re.sub()

In this Python article, you will learn how to perform the search and replace operations on a Python string using regular expressions. The regular expression in Python provides more methods and techniques to match the patterns and perform operations on a string than a simple string method. This tutorial discusses regular expression sub() and subn() methods that can… Read More »

Longest Substring without repeating characters

Problem Given a string, find the longest substring with unique characters Sample Input “abcdd” Sample Output 4 Explanation The longest substring with unique characters is “abcd” resulting 4 unique letters. Approach The idea is to scan the string from left to right, keeping track of the longest non-repeating character substring seen so far. When traversing the string, we… Read More »

String Formatting using format in Java

Introduction We usually use System.out.println or System.err.println to print messages on the console. But to use the printf formatting options, we can use the System.out.format methods or System.err.format methods. Formatting output with System.out.format Formatting output using above methods will eliminate the plus signs we otherwise use to merge the values together and make the code more readable and… Read More »