簡體   English   中英

C#中的通配符字符串替換

[英]Wildcard string replace in C#

我有一個大文件引用其中的URL。 它始終具有以下格式:

 URL="........." - where the ellipses are the URL.

我有一個新的URL想要替換以前的,我想知道是否有任何種類的通配符替換。

Example:
A large string contains: URL="google.com"

Problem: 
I need to replace the above with: URL="123.com"

謝謝你的幫助

嘗試這個:

string largeString = ".....URL=\"google.com\" ....";
string pattern = "URL=\"([^ \"]*)\"";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(largeString, "URL=\"123.com\"");
Regex.Replace(line, @"URL\s*=\s*"".+?""", @"URL=""123.com""");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM