第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

刪除字符串開頭和結(jié)尾之間的部分

刪除字符串開頭和結(jié)尾之間的部分

C#
FFIVE 2023-08-20 10:10:48
首先代碼:   string myString = "<at>onePossibleName</at> some question here regarding <at>disPossibleName</at>"    // some code to handle myString and save it in myEditedString    Console.WriteLine(myEditedString);    //output now is: some question here regarding <at>disPossibleName</at>我想<at>onePossibleName</at>從 myString 中刪除。該字符串onePossibleName可以disPossbileName是任何其他字符串。到目前為止我正在與string myEditedString = string.Join(" ", myString.Split(' ').Skip(1));這里的問(wèn)題是,如果onePossibleName變成one Possible Name。嘗試也是如此myString.Remove(startIndex, count)- 這不是解決方案。
查看完整描述

3 回答

?
嗶嗶one

TA貢獻(xiàn)1854條經(jīng)驗(yàn) 獲得超8個(gè)贊

根據(jù)你想要的,會(huì)有不同的方法,你可以使用 IndexOf 和 SubString,正則表達(dá)式也是一個(gè)解決方案。


// SubString and IndexOf method

// Usefull if you don't care of the word in the at tag, and you want to remove the first at tag

if (myString.Contains("</at>"))

{

    var myEditedString = myString.Substring(myString.IndexOf("</at>") + 5);

}

// Regex method

var stringToRemove = "onePossibleName";

var rgx = new Regex($"<at>{stringToRemove}</at>");

var myEditedString = rgx.Replace(myString, string.Empty, 1); // The 1 precise that only the first occurrence will be replaced



查看完整回答
反對(duì) 回復(fù) 2023-08-20
?
白衣非少年

TA貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個(gè)贊

string myString = "<at>onePossibleName</at> some question here regarding <at>disPossibleName</at>"


int sFrom = myString.IndexOf("<at>") + "<at>".Length;

int sTo = myString.IndexOf("</at>");


string myEditedString = myString.SubString(sFrom, sFrom - sTo);

Console.WriteLine(myEditedString);

//output now is: some question here regarding <at>disPossibleName</at>


查看完整回答
反對(duì) 回復(fù) 2023-08-20
?
哆啦的時(shí)光機(jī)

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊

您可以使用這個(gè)通用正則表達(dá)式。


var myString = "<at>onePossibleName</at> some question here regarding <at>disPossibleName</at>";

var rg = new Regex(@"<at>(.*?)<\/at>");

var result = rg.Replace(myString, "").Trim();

這將刪除所有“at”標(biāo)簽及其之間的內(nèi)容。該Trim()調(diào)用是在替換后刪除字符串開頭/結(jié)尾處的所有空格。


查看完整回答
反對(duì) 回復(fù) 2023-08-20
  • 3 回答
  • 0 關(guān)注
  • 183 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)