亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在字符串中查找子字符串,項目后跟搜索的句子

在字符串中查找子字符串,項目后跟搜索的句子

C#
慕田峪7331174 2021-10-09 10:40:44
在 C# 中找到字符串中的子字符串并使用單詞后跟搜索的句子來檢索它的正確方法是什么,例如在字符串中: string str = "On the screen the faint, old, robed figure of Mercer toiled upward, and all at once a rock sailed past him.";搜索子串: string find = "figure of";獲得所需的輸出: figure of Mercer
查看完整描述

1 回答

?
慕標琳琳

TA貢獻1830條經驗 獲得超9個贊

你可以試試這個模式 ([inputString] +(\\w+))


使用正則表達式group和空格來獲取單詞。


string search = "figure of";

string str = "On the screen the faint, old, robed figure of Mercer toiled upward, and all at once a rock sailed past him.";

string regex_Str = string.Format("({0} +([\\w+]+))", search);

var result = new Regex(regex_Str).Match(str);

Console.WriteLine(result.Value);


查看完整回答
反對 回復 2021-10-09
  • 1 回答
  • 0 關注
  • 150 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號