110,502
社区成员
发帖
与我相关
我的任务
分享
private string _GetStr(string str,string matchStr,string quoteStr)
{
int index = str.IndexOf(matchStr);
string value = "";
while (index >= 0)
{
if (value != "")
{
value += ",";
}
value += _MappingStr(ref str, matchStr, quoteStr,index);
index = str.IndexOf(matchStr);
}
return value;
}
private string _MappingStr(ref string str, string matchStr, string quoteStr,int index)
{
int startIndex = -1;
int endIndex = -1;
startIndex = str.Substring(index, str.Length - index).IndexOf(quoteStr);
if (startIndex > 0)
{
startIndex += index + 1;
}
endIndex = str.Substring(startIndex + 1, str.Length - startIndex - 1).IndexOf(quoteStr);
if (endIndex > 0)
{
endIndex += startIndex;
}
if (startIndex >= 0 && endIndex >= 0)
{
string value = str.Substring(startIndex, endIndex - startIndex + 1);
str = str.Substring(endIndex+1, str.Length - endIndex-1);
return value;
}
else
{
return "";
}
}
//调用
string str = "asdfd23fej +==fief1423difjj usedID=\"92\"dfdifj\"A\"adfd fdfe usedID=\"123\"dref";
str = _GetStr(str, "usedID", "\"");
string str = "asdfd23fej +==fief1423difjj usedID=\"92\"dfdifj\"A\"adfd fdfe usedID=\"123\"dref";
var ary = Regex.Matches(str, @"(?i)(?<=usedid=([""']?)\d+(?=\1)).OfType<Match>().Select(t => Convert.ToInt32(t.Value)).ToArray();
string[] arr = s.Split(' ');
foreach(string str in arr)
{
if(str.Length>7 && str.Substring(0,7).Equals("userId="))
{
string userId = str.split('=').Trim('\"');
//对取出的userId进行处理
}
}