. NET, use formal expression matching to get the data you need
Requirement: Gets a string of strings, and the regular matches the required data.
For example, the following string:
String temp = "errorcode:-1,message:{" UserId ":" "N", "UserName": "Zhangsan"} ";
I need to get "-1" and "{" UserId ":" "," "UserName": "Zhangsan"} ";
Next, use regular to match:
Using system.text.regularexpressions;string temp = "errorcode:-1,message:{\" userid\ ": \" 1000\ ", \" username\ ": \" Zhangsan\ "}"; Regex reg = new Regex ("ErrorCode: (? <key1>.*?), message:{(? <key2>.*?)}"); Match match = Reg. Match (temp); string tempstr = match. groups["Key1"]. Value + "--" + match. groups["Key2"]. Value; MessageBox.Show (TEMPSTR);
At this time tempstr get is " -1--{" UserId ":" "," "UserName": "Zhangsan"} "
In C #, use formal expression matching to get the data you need