在大括号内分割字符串 [英] spliting a string within braces

查看:169
本文介绍了在大括号内分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串格式如shakun(shrestha)

我需要分别将子字符串检索为"shakun"和"shrestha"

我尝试使用split函数,但我的输出是shrestha)

这是我尝试过的代码段.

i have a string formatted like shakun(shrestha)

I need to retrieve sub string as "shakun" and "shrestha" seperately

i tried to using the split function but my output was shrestha)

here the code snippet i tried.

string test = "shakun(shrestha)";
string s = test.Split('(')[1];


任何帮助将不胜感激:)


Any help would be appreciated :)

推荐答案

string test = "shakun(shrestha)";
test = test.Replace("(", "|");
test = test.Replace(")", "|");
string[] arr = test.Split('|');
foreach (string s in arr)
{
    //do what you want here.

}




试试这个


Hi,

Try this


string test =shakun(shrestha);
            string s = test.Split('(',')')[1];


希望对您有所帮助,

Hope it helps,

string test = "shakun(shrestha)";
           
string[] s = test.Split(new char[] { '(', ')' }, StringSplitOptions.None).Where(item => item != string.Empty).ToArray<string>();


:)


这篇关于在大括号内分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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