开发者

Regex Question

In my C# Console App I'm trying to use Regex to search a string to determine if there is a ma开发者_如何转开发tch or not. Below is my code but it is not quite working right so I will explain further. sSearchString is set to "_One-Call_Pipeline_Locations" and pDS.Name is a filename it is searching against. Using the code below it is set to true for Nevada_One-Call_Pipeline_Locations and Nevada_One-Call_Pipeline_LocationsMAXIMUM. There should be a match for Nevada_One-Call_Pipeline_Locations But Not for Nevada_One-Call_Pipeline_LocationsMAXIMUM. How can I change my code to do this properly?

Thanks in advance

if (Regex.IsMatch(pDS.Name, sSearchString))


Change the sSearchString to ".*_One-Call_Pipeline_Locations$"


You need to specify that a matching name must end with the text you have entered using the dollar token.

sSearchString = "_One-Call_Pipeline_Locations$";


Since you provided no details as to what else should match, we can only assume that if the string ends with "Nevada_One-Call_Pipeline_Locations", then it matches? Is this correct?

If so, you don't need Regex:

if (pDS.Name.EndsWith("Nevada_One-Call_Pipeline_Locations"))
{ //...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜