Programming 

A Guide to the Newer Python String Format Techniques

In the previous tutorial in this introductory series, you learned how to format string data using the string modulo operator. The string modulo operator is useful, and it’s good for you to be familiar with it because you’re likely to encounter it in older Python code. However, there are two newer ways that you can use Python to format strings that are arguably more preferable. In this tutorial, you’ll learn about: The string .format() method The formatted string literal, or f-string You’ll learn about these formatting techniques in detail and…

Read More

How to Convert Python String to Int and Back to String

This tutorial describes various ways to convert Python string to int and from an integer to string. You may often need to perform such operations in day to day programming. Hence, you should know them to write better programs. Also, an integer can be represented in different bases, so we’ll explain that too in this post. And there happen to be scenarios where conversion fails. Hence, you should consider such cases as well and can find a full reference given here with examples. By the way, it will be useful…

Read More
java 

Top 20 String Algorithm Questions from Coding Interviews

In this article, we are going to see top 20 String based coding interview question and their solution to help programmers better prepare for interviews. The string is one of the most important data structure and available in almost every programming language like Java, C, C++, Python, Perl, and Ruby. Though there implement differ the essence remains same like String is NULL terminated character array in C but String is an object in Java, again backed by character array. The string is also available on weekly typed languages like Python and…

Read More
java 

String comparisons in Java

In Java, the String class encapsulates an array of char. Put simply, String is an array of characters used to compose words, sentences, or any other data you want. Encapsulation is one of the most powerful concepts in object-oriented programming. Because of encapsulation, you don’t need to know how the String class works; you just need to know what methods to use on its interface. When you look at the String class in Java, you can see how the array of char is encapsulated: To read this article in full,…

Read More

String interpolation in Python and R

One of the things I liked about Perl was string interpolation. If you use a variable name in a string, the variable will expand to its value. For example, if you a variable $x which equals 42, then the string “The answer is $x.” will expand to “The answer is 42.” Perl requires variables to start with sigils, like the $ in front of scalar variables. Sigils are widely considered to be ugly, but they have their benefits. Here, for example, $x is clearly a variable name, whereas x would…

Read More

Mocking JDBC Using a Set of SQL String / Result Pairs

In a previous blog post, I’ve shown how the programmatic MockDataProvider can be used to mock the entire JDBC API through a single functional interface: // context contains the SQL string and bind variables, etc. MockDataProvider provider = context -> { // This defines the update counts, result sets, etc. // depending on the context above. return new MockResult[] { … } }; Writing the provider manually can be tedious in some cases, especially when a few static SQL strings need to be mocked and constant result sets would be…

Read More
java 

2 Ways to Check if a String is Rotation of Other in Java – Algorithms

Write a program to check if one String is a rotation of another String is a common coding problem you will find on programming job interviews.  A String is said to be a rotation of another String, if it has the same length, contains the same characters, and they were rotated around one of the characters. For example,  String"bcda" is a rotation of "abcd" but "bdca" is not a rotation of String "abcd". One of the simplest solutions to this interesting problem is first to check if two String has the…

Read More

JavaScript Reverse String – 4 Ways

In this tutorial I will talk about how you can reverse a string in JavaScript language. This is a very popular question i.e. asked in interviews. There are many ways in which we can reverse a string. Here I will discuss different ways in which we can achieve this. JavaScript Reverse String Using Buitin Function To reverse a string using built-in methods we have to chain some methods like join, split and reverse. For this first, we need to convert the string into an array by using split method then…

Read More

Multiline String in Python with Examples

This tutorial explains how to create a Python multiline string. It can be handy when you have a very long string. You shouldn’t keep such text in a single line. It kills the readability of your code. In Python, you have different ways to specify a multiline string. You can have a string split across multiple lines by enclosing it in triple quotes. Alternatively, brackets can also be used to spread a string into different lines. Moreover, backslash works as a line continuation character in Python. You can use it…

Read More

Find minimum number of deletions required to convert a string into a palindrome

Given a string, find minimum number of deletions required to convert it into a palindrome.   For example, consider the string ACBCDBAA. The minimum number of deletions required are 3 A C B C D B A A   or   A C B C D B A A   —>   A B C B A     The idea is to use recursion to solve this problem. The … The post Find minimum number of deletions required to convert a string into a palindrome appeared first on Techie Delight.

Read More