开发者

Help With pattern matching

开发者 https://www.devze.com 2023-02-11 00:25 出处:网络
In my code I have to match below 3 types of data abcd:xyz:def def:xyz xyz:def where \"xyz\" is the real data and other part are Junk data. Now, for first 2 types as below I can split with \':\' and

In my code I have to match below 3 types of data

abcd:xyz:def
def:xyz
xyz:def

where "xyz" is the real data and other part are Junk data. Now, for first 2 types as below I can split with ':' and can get the array[1] position data ... which will give me the correct one.

开发者_如何转开发abcd:xyz:def
def:xyz

I am not getting How can extract the 3rd case. Any idea? Please help.

Thanks, Rahul


string case1 = "abcd:xyz:def";
string case2 = "def:xyz";
string case3 = "xyz:def";

string result1 = case1.Split(':')[1];
string result2 = case2.Split(':')[1];
string result3 = case3.Split(':')[0];

If I understand your question correctly.


Use array[0] instead of array[1] in the third case after splitting.

0

精彩评论

暂无评论...
验证码 换一张
取 消