我有一個字符串,它是一個REST查詢字符串,它看起來像這樣正則表達式使用
//new_requestSet?$select=new_ExternalStatus,new_name&$filter=new_ExternalStatusDirty eq true
我使用StackOverflow上發佈here正則表達式類。它能很好地在上面的輸入字符串中找到一些位置,但我覺得我的代碼能夠提取我需要的實際值是低效的。有沒有更有效的方式使用正則表達式而不是IndexOf和SubString?
int fieldPos = StringExtender.NthIndexOf(json, "filter=", 1);
int firstSpace = StringExtender.NthIndexOf(json, " ", 1);
int secondSpace = StringExtender.NthIndexOf(json, " ", 2);
int entityPosEnd = StringExtender.NthIndexOf(json, @"\Set", 1);
int searchFieldStart = StringExtender.NthIndexOf(json, "=", 2);
string searchField = json.Substring(searchFieldStart + 1, firstSpace - searchFieldStart - 1);
string criteria = json.Substring(secondSpace+1);
string entity = json.Substring(0, entityPosEnd);
感謝鮑勃偉大的建議,我沒有注意到。 – GoBeavs