我有一个字符串
string a = "(something is there),xyz,(something there)";
Run Code Online (Sandbox Code Playgroud)
而且,我用这个
string s = "(something is there),xyz,(something there)";
int start = s.IndexOf("(") + 1;
int end = s.IndexOf(")", start);
string result = s.Substring(start, end - start);
Run Code Online (Sandbox Code Playgroud)
但是我想用第二部分(something there)
怎么做呢?
不确定你到底在做什么,但是在这种特殊情况下这样做:
var last = s.Split(',').Last(); // "(something there)"
Run Code Online (Sandbox Code Playgroud)
或者更详细地解释:
var s = "(something is there),xyz,(something there)";
var split = s.Split(','); // [ "(something is there)", "xyz", "(something there)" ]
var last = split.Last(); // "(something there)"
Run Code Online (Sandbox Code Playgroud)
如果你不想要括号(en-GB)
var content = last.Trim('(', ')'); // "something there"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1089 次 |
| 最近记录: |