获取大括号之间的值 c# [英] Get values between curly braces c#
本文介绍了获取大括号之间的值 c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以前从未使用过正则表达式.我在论坛上看到了类似的问题,但不完全是我在找什么
I never used regex before. I was abel to see similar questions in forum but not exactly what im looking for
我有一个像下面这样的字符串.需要获取大括号之间的值
I have a string like following. need to get the values between curly braces
例如:{name}{name@gmail.com}"
Ex: "{name}{name@gmail.com}"
我需要得到以下拆分的字符串.
And i Need to get the following splitted strings.
姓名和姓名@gmail.com
name and name@gmail.com
我尝试了以下操作,它返回了相同的字符串.
I tried the following and it gives me back the same string.
string s = "{name}{name@gmail.com}";
string pattern = "({})";
string[] result = Regex.Split(s, pattern);
推荐答案
是否必须使用正则表达式?在这个特定的例子中,我会写:
Is using regex a must? In this particular example I would write:
s.Split(new char[] { '{', '}' }, StringSplitOptions.RemoveEmptyEntries)
这篇关于获取大括号之间的值 c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文