Tag: String
C++ : How to check if a String Ends With an another given String
In this article we will discuss both case sensitive and insensitive implementations to check if a string ends with an another given string. In previous article we discussed different implementations of startsWith() function for std::string. Here on similar lines we will discuss different implementations of endsWith() function. Advertisements In c++, std::string class does not provides any …
C++ : How to check if a String Ends With an another given StringRead More
How to remove Substrings from a String in C++
In this article we will discuss how to remove single or multiple sub strings from a given string. std::string class provides a member function string::erase() to remove some characters from a given position i.e. Advertisements string& erase (size_t pos = 0, size_t len = npos); It accepts a position and length of characters to be …
C++: How to extract file extension from a path string using Boost & C++17 FileSystem Library
In this article we will dicuss different ways to extract extension from a given path string using different technique i.e. C++17 FileSystem Library Boost FileSystem Library C++ STL Suppose given file is, Advertisements /home/user/sample/temp/logs.out It’s extension should be .out. Fetch extension of a given file using Boost Filesystem Library & C++17 Both boost filesystem library …
C++ : Case-insensitive string comparison using STL | C++11 | Boost Library
In this article we will discuss different ways to Compare strings in case insensitive manner. Suppose we have two strings i.e. Advertisements std::string str1 = “Hi This is SamPle”; std::string str2 = “hi this is sample”; Both the above strings should be equal if we compare them in case insensitive manner. Let’s see how to …
C++ : Case-insensitive string comparison using STL | C++11 | Boost LibraryRead More
Convert list to string in python using join() / reduce() / map()
In this article we will discuss different ways to convert list to string. Convert list to string in python using join() in python In python string class provides a function join() i.e. Advertisements string.join(iterable) join() function accepts an iterable sequence like list or tuple etc as an argument and then joins all items in this …
Convert list to string in python using join() / reduce() / map()Read More
Python : How to access characters in string by index ?
In this article we will discuss how to access characters in string by index. Accessing characters by index in string | indexof In Python indexing of strings starts from 0 till n-1, where n is the size of string. So characters in string of size n, can be accessed from 0 to n-1. Advertisements Suppose we …
Python : How to access characters in string by index ?Read More
Python : How to iterate over the characters in string ?
In this article we will discuss different ways to iterate or loop over all the characters of string in forward, backward direction and also by skipping over certain characters. Iterate over string using for loop Iterating over the string is simple using for loop and in operator i.e. Advertisements sampleStr = “Hello!!” print(“**** Iterate over …
Python : How to iterate over the characters in string ?Read More
Python : How to replace single or multiple characters in a string ?
In this article we will discuss how to replace single or multiple characters in a string in Python. Python provides a str.replace() function i.e. Advertisements str.replace(old, new , count) It returns a new string object that is a copy of existing string with replaced content. Also, If count is not provides then it will return …
Python : How to replace single or multiple characters in a string ?Read More
Python : How to convert a timestamp string to a datetime object using datetime.strptime()
In this article we will discuss how to convert timestamp in different string formats to a datetime class object in Python. String to datetime object using datetime.strptime() Python’s datetime module provides a datetime class, which has a method to convert string to a datetime object i.e. Advertisements datetime.strptime(date_string, format) If accepts a string containing the …
Python : How to convert a timestamp string to a datetime object using datetime.strptime()Read More
Python : How to convert datetime object to string using datetime.strftime()
In this article we will discuss how to convert a datetime class object to different string formats using datetime.strftime() function. datetime.strftime() Python’s datetime class provides a member function strftime() to create string representation of data in the object i.e. Advertisements datetime.strftime(Format_String) It accepts a format string as argument and converts the data in object to …
Python : How to convert datetime object to string using datetime.strftime()Read More