Found 33676 Articles for Programming

Tokenizing a string in C++

Farhan Muhamed
Updated on 13-Jun-2025 18:51:05

7K+ Views

Tokenization refer to the process of breaking a string based on certain delimiters such as spaces, commas, semicolons, or any other character. Mostly white spaces are used as delimiters to tokenize strings. In this article, we will discuss all the ways tokenize a string in C++. For example, if we have a string like "Hello, World! Welcome to Tutorialspoint.", we can tokenize it like this: string str = "Hello, World! Welcome to Tutorialspoint."; tokens = {"Hello", "World", "Welcome", "to", "Tutorialspoint"}; Tokenizing a String in C++ In C++, we can tokenize a string using various methods. Here are ... Read More

The most elegant way to iterate the words of a string using C++

Anvi Jain
Updated on 30-Jul-2019 22:30:25

156 Views

There is no one elegant way to iterate the words of a C/C++ string. The most readable way could be termed as the most elegant for some while the most performant for others. I've listed 2 methods that you can use to achieve this. First way is using a stringstream to read words separated by spaces. This is a little limited but does the task fairly well if you provide the proper checks. For example, >Example Code Live Demo#include #include #include #include using namespace std; int main() {    string str("Hello from the dark side");   ... Read More

String tokenisation function in C

Smita Kapse
Updated on 30-Jul-2019 22:30:25

6K+ Views

In this section, we will see how to tokenize strings in C. The C has library function for this. The C library function char *strtok(char *str, const char *delim) breaks string str into a series of tokens using the delimiter delim.Following is the declaration for strtok() function.char *strtok(char *str, const char *delim)It takes two parameters. The str - The contents of this string are modified and broken into smaller strings (tokens), and delim - This is the C string containing the delimiters. These may vary from one call to another. This function returns a pointer to the first token found ... Read More

string at() function in C++

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

145 Views

In this section, we will see what is the at a () function in C++. The at() function is used to access the character at a given position.In this program, we will iterate through each character using at a () function and print them into different lines.Example Code Live Demo#include using namespace std; main() {    string my_str = "Hello World";    for(int i = 0; i

How to remove certain characters from a string in C++?

Farhan Muhamed
Updated on 09-Jun-2025 19:09:19

88K+ Views

In this section, we will see how to remove some characters from a string in C++. In C++ we can do this task very easily using erase() and remove() function. The remove function takes the starting and ending address of the string, and a character that will be removed. // Input String = "Hello TutorialsPoint" Char = 'o' // Output String = "Hell TutrialsPint" Algorithm to Remove Certain Characters from a String Here is the algorithm to remove certain characters from a string in C++: Step 1: Take a string and a character to be removed ... Read More

How to quickly reverse a string in C++?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

358 Views

In this section, we will see how to reverse a string very quickly using C++. For reversing there is a built-in function in the algorithm library, called reverse(). This function takes the beginning and the ending pointer of a container, then reverse the elements.Input: A number string “Hello World” Output: “dlroW olleH”AlgorithmStep 1:Take a string Step 2: reverse it using reverse() function Step 3: Print the result. Step 4: EndExample Code Live Demo#include #include using namespace std; main() {    string my_str = "This is a string to be reversed";    cout

How to map C++ enums to strings?

Farhan Muhamed
Updated on 06-Jun-2025 18:58:17

3K+ Views

Here we will see how to map enum type data to a string in C++ There is no such direct function to do so. But we can create our own function to convert enum to string. We shall create a function that takes an enum value as the argument, and we manually return the enum names as a string from that function. First of all, let us understand what is an enum in C++. What is an Enum in C++? Enum is a user-defined datatype in C++ that is used to assign names to integer values. For example, you ... Read More

How to convert std::string to lower case in C++?

Farhan Muhamed
Updated on 04-Jun-2025 18:48:16

9K+ Views

The STL library in C++ provides various inbuilt functions and methods to manipulate strings, such as converting them to lower case or upper case. In this article, we will learn all the approaches to convert a std::string to lower case in C++. First of all, let's understand the problem statement. In this problem, you are given a string as input and you need to convert it to lower case. The string may contain any type of characters such as letters, digits, and special characters. For example: // Input String std::string str = "Hello World! 123 @ TutorialsPoint"; // ... Read More

How to drop a table from a database using JDBC API?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

1K+ Views

A. The SQL DROP TABLE statement is used to remove a table definition and all the data, indexes, triggers, constraints and permission specifications for that table.SyntaxDROP TABLE table_name;To drop an table from a database using JDBC API you need to:Register the driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using the createStatement() method of the Connection interface.Execute the Query: Execute ... Read More

How to convert an enum type variable to a string in C++?

Farhan Muhamed
Updated on 06-Jun-2025 18:57:32

558 Views

Enum is a user-defined datatype in C++ that is used to assign names to integer values. For example, you can use an enum to represent the days of the week from 0 to 6, where 0 represents Sunday, 1 represents Monday, and so on. When you try to access a value of an enum, it will only return an integer value. In this article, we will learn how to convert an enum type variable to a string type variable in C++, so that we can easily display the enum value as a string. Example of Enum: enum color ... Read More

Advertisements