2012-09-14 94 views
0

我有一個字符串,它是一個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); 
+0

感謝鮑勃偉大的建議,我沒有注意到。 – GoBeavs

回答

0

可以通過「&」第一次吐你串和接收參數的名稱/值對
然後由「=」每對分裂第二時間和接收參數名稱/值的不同值。

你需要編寫更多的代碼,但根本沒有任何正則表達式。