使用Regex.Matches
我的印象是,你會進入一些這樣:Regex.Matches沒有返回預期
private static int CheckForWordMatch(string offer, string item)
{
string pattern = @"\b(" + item + ")\b";
int count = 0;
count = Regex.Matches(@offer, pattern).Count;
return count;
}
測試參數:
offer = AK47HyperBeastFieldTested
item = AK47HyperBeastFieldTested
我在尋找確切的詞匹配所以如果物品是「AK47HyperBeast」,它不會返回匹配計數2.
我在這裏做錯了什麼?
他錯過了另一部分'@'右...........錯過+1 – vks
非常感謝您提供清晰簡潔的解釋。並補充一點,所以我實際上錯過了一個'@'逐字串指示符!我已經清理了'item'字符串和'offer'字符串以僅包含字母,謝謝您提供更多信息。 – MattGarnett
@MattGarnett:不用客氣,連接字符串時很容易忘記'@'符號。 –