![](/img/trans.png)
[英]How to check in C# if a specific word or another specific word exists in a text using regular expression
[英]c# algorithm to check if a specific “word” exists in url
我有一個網址:
http://www.domain.com/path/path/path/path/file1.html
然后再一個:
http://www.domain.com/path/path/external/path/path/file1.html
請注意路徑中的/external/
。
現在,文件“相同”,但是基於/external/
它們針對不同的受眾。 如果路徑包含/ external /,則該路徑供外部使用,否則供內部使用。
我的問題是如何將這兩個文件相互關聯? “ / external /”可以位於路徑內的任何位置。
每個文件最多只能有一個外部類型,或者根本沒有。
現在將路徑映射到它的外部類型,我想這樣做:
對於特定文件:
http://www.domain.com/path/path/path/path/file1.html
/external/
作為列表的所有文件路徑
/external/
好吧,實際上您不必將包含/external/
所有文件路徑添加到列表中。 您可以簡單地使用String.Replace
方法。
string targetPath = "http://www.domain.com/path/path/external/path/path/file1.html";
targetPath = targetPath.Replace("/external/", "/");
這將用單個/
替換字符串中的所有/external/
部分。 而且,如果該字符串不包含任何/external/
字符串,則它只會替換任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.