No more nonsense, go straight to the point:
The question is: is such a string, "dfsdg<2434>,dgdfg<35346>,dtr35<3w543>", extracting the contents of "<" and ">"?
The first thing we should think about is to group them out first, then to judge the position of the angle bracket, and then we can intercept it. So I used the premise of two different ways to achieve, as follows:
1, the original string interception mode, the sample code is as follows:
Copy Code code as follows:
String str= "dfsdg<2434>,dgdfg<35346>,dtr35<3w543>";
String[] Strgroup=str. Split (', ');
foreach (var s in Strgroup)
{
int Left=s.indexof (' < ');
int Right=s.lastindexof (' > ');
S.substring (left+1,right-left-1);
Console.WriteLine (s);
}
The results of the operation are as follows:
2434
35346
3w543
2, Application Language integration query (LINQ), the sample code is as follows:
Copy Code code as follows:
String str= "dfsdg<2434>,dgdfg<35346>,dtr35<3w543>";
var result=from s in Str. Split (', ')
Let Left=s.indexof (' < ')
Let Right=s.lastindexof (' > ')
Select S.substring (left+1,right-left-1);
Result. Dump ();
The results of the operation are as follows:
The second type of debugging tool is debugged using LINQPad. For the second let keyword, the help document is explained as follows:
The Let keyword can create a new range variable and initialize the variable with the result of the expression you provide. Once the range variable is initialized with a value, it cannot be used to store other values. However, if the range variable stores a type that can be queried, it can be queried.
Well, for this problem I summed up here, I hope to help others, but also welcome everyone has a better way and ideas to solve this problem, welcome to leave a message, I will be grateful!