I have a char list:
var myList = new List<char>(new[] { 'x', 'y', '(', 'a', 'b', 'c', ')', 'z' });
Run Code Online (Sandbox Code Playgroud)
With the values:
'x'
'y'
'('
'a'
'b'
'c'
')'
'z'
Run Code Online (Sandbox Code Playgroud)
How can i take all the values between the braces? The values in new list should look like this:
'a'
'b'
'c'
Run Code Online (Sandbox Code Playgroud)
The index of the braces in the list can change every session.
You can use this LINQ expression:
myList.SkipWhile(c => c != '(').Skip(1).TakeWhile(c => c != ')')
^----- 1 --------------^ ^- 2 -^ ^-------- 3 -----------^
Run Code Online (Sandbox Code Playgroud)
(( we found) (which will not be included)Notes:
| 归档时间: |
|
| 查看次数: |
71 次 |
| 最近记录: |