Home > Backend Development > C++ > How Can I Extract Text from Parentheses Without Using Regular Expressions?

How Can I Extract Text from Parentheses Without Using Regular Expressions?

Susan Sarandon
Release: 2025-01-18 03:06:07
Original
146 people have browsed it

How Can I Extract Text from Parentheses Without Using Regular Expressions?

Extract text from brackets

Question:

Getting what is contained within the brackets (round brackets) from a given string can be a challenge. Consider the string "username(sales)" and the goal is to extract the text from the brackets. How can I achieve this without relying on regular expressions?

Answer:

To extract the text inside brackets without using regular expressions, a straightforward approach involves splitting the input string:

<code>string input = "用户名 (销售)";
string[] parts = input.Split('(', ')');
string output = parts[1];</code>
Copy after login

This split operation creates an array where each element represents a string segment separated by bracket characters. The second element of the array (parts[1]) contains the text within the brackets, which can then be assigned to the output variable.

The above is the detailed content of How Can I Extract Text from Parentheses Without Using Regular Expressions?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template