File manipulation is a fundamental aspect of programming, especially when dealing with data processing and management. Python offers powerful tools for handling files and text efficiently. A common task is searching for specific text patterns within a file and replacing them with desired content. This article explores several practical methods for searching and replacing text in a file using Python. Basic Text Replacement Let's start with a simple example of searching for a specific word in a file and replacing it with another word. In this particular example, we'll search for the word "old" and replace it with "new" − ... Read More
Hard links in Python can be created using several methods. Hard links allow you to create multiple names for the same file on the filesystem, meaning changes made to one will reflect in the other. Below are three methods to create hard links. Using os.link() Using os.system() with Shell Command Using subprocess.run() Using 'os.link()' Method The most straightforward way to create a hard link in Python is by using the os.link() method, which is built into the OS module. This method takes two arguments: the source file (`src`) ... Read More
Gradient borders add a modern and visually appealing touch to web elements, making them stand out. However, achieving this effect in CSS isn’t straightforward because the border property doesn’t natively support gradients. This article explores practical workarounds to implement gradient borders, ensuring your designs remain vibrant and dynamic. We’ll cover three methods, complete with code examples and outputs, to help you master this technique. Prerequisites Before diving into gradient borders, ensure you have: Basic HTML Knowledge: Familiarity with creating elements like . CSS Fundamentals: Understanding properties like border, background, and ... Read More
In this article, we will learn to focus on a particular element with a div class in JavaScript. In JavaScript setting focus on an element is commonly done using the focus() method. What is the focus() method? The focus() method in JavaScript is used to bring a specific element into focus. This means the element becomes active, allowing the user to interact with it, such as typing in an input field or highlighting a section of the webpage. Syntax element.focus(); Here, the element is the DOM element that will receive the focus. Using JavaScript to Focus on a Class Element ... Read More
In this article, we will learn to subtract 40 days from the calendar in Java. Working with dates is a frequent need in programming, and there are multiple methods of doing it in Java. One of the simplest approaches is to use the Calendar class to remove days from a date. Different Approaches The following are the two to subtract 40 days from the calendar in Java − Using the Calendar Class Using the LocalDate Class Using the Calendar Class The first approach utilizes the Calendar class, which is part ... Read More
Artificial Intelligence is a study of agents that act rationally. These agents often implement a search algorithm to find the goal. A search algorithm consists of Goal state - final destination in the task search space - all available states of the problem initial state - the starting point of the problem There are two sets of search algorithms: Uninformed Search, Informed Search Uninformed search This is also commonly known as blind search. In this type of search, no additional information is provided other than ... Read More
In this article, we will learn to generate all rotations of a number in JavaScript. Producing a primary common problem such as all its rotations comprises the creation of all possible permutations of the digits by rotating its digits. Problem Statement The goal is that if we have given a number, we need to generate all possible rotations of its digits. A rotation is defined as moving the first digit to the end of the number. For exampleInput 123 Explanation 123 (original number) 231 (first rotation: move 1 to the ... Read More
In this article, we will learn to map a String list to lowercase and sort in Java. We need to manipulate the elements of a list, such as converting all strings to lowercase and sorting them. This is particularly useful when dealing with user input, file processing, or data normalization. Problem Statement Given a list of strings, we want to convert all strings to lowercase and sort the list in reverse alphabetical order.For Example: Input ["Apple", "banana", "Cherry", "date"] Output ["date", "cherry", "banana", "apple"] Using Streams API The Streams API provides a useful and functional approach to processing ... Read More
In this article, we will learn to display the date and time in uppercase using Java. Working with date and time in Java is a common requirement in various applications, logging, scheduling, or data processing. Different Approaches The following are the two different approaches to display the date and time in uppercase using Java − Using Formatter and Calendar Using DateTimeFormatter Using Formatter and Calendar The Formatter class in Java allows us to format date and time using the %Tc specifier. We can then convert the output to uppercase using ... Read More
The task is to write C++ programs that calculates the sum of the digits of a given number. For example, if the number is 453, the sum of its digits would be 4 + 5 + 3 = 12. To solve this, we will extract each digit from the number and add them together. We will use basic programming concepts such as loops and arithmetic operations to achieve this. In this article, we will show you how to write a C++ program that takes a number as input and sums the digits of that number. Approaches for ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP