如何提取位于括号(圆括号)之间的文本? [英] How do I extract text that lies between parentheses (round brackets)?

查看:37
本文介绍了如何提取位于括号(圆括号)之间的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串 User name (sales) 我想提取括号之间的文本,我该怎么做?

I have a string User name (sales) and I want to extract the text between the brackets, how would I do this?

我怀疑是子字符串,但在结束括号之前我无法弄清楚如何阅读,文本的长度会有所不同.

I suspect sub-string but I can't work out how to read until the closing bracket, the length of text will vary.

推荐答案

如果你想远离正则表达式,我能想到的最简单的方法是:

If you wish to stay away from regular expressions, the simplest way I can think of is:

string input = "User name (sales)";
string output = input.Split('(', ')')[1];

这篇关于如何提取位于括号(圆括号)之间的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆