获得大括号C#之间的值 [英] Get values between curly braces c#

查看:623
本文介绍了获得大括号C#之间的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有使用正则表达式。我是亚伯看到论坛上类似的问题,但不完全是即时寻找



我有一个像下面的字符串。需要得到大括号




前值:{} name}{name@gmail.com




,我需要得到以下分裂字符串。




名称和name@gmail.com




我尝试以下,这让我回到相同的字符串。

 字符串s ={} name}{name@gmail.com; 
字符串模式=({});
的String []结果= Regex.Split(S,图案);


解决方案

时,使用正则表达式必须的?在这个特殊的例子,我会写:

  s.Split(新的char [] {'{','}}, StringSplitOptions.RemoveEmptyEntries)


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

Ex: "{name}{name@gmail.com}"

And i Need to get the following splitted strings.

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屋!

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