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

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

如何使用方法替換特定字符串?

如何使用方法替換特定字符串?

C#
HUX布斯 2023-08-20 09:49:08
我的代碼有問(wèn)題,我想將特定字符串替換為新字符串,但它不起作用public void InsertYahoo(TextBox sender){    if (IsGmail(sender))    {        ReplaceGmail(sender);    }    else if(IsYahoo(sender))    {        return;    }    else    {        sender.Text +="@yahoo.com";    }}public bool IsYahoo(TextBox sender){    if (sender.Text.Contains("@yahoo.com")    {        return true;    }    else    {         return false;    }}public bool IsGmail(TextBox sender){     if (sender.Text.Contains("@gmail.com")     {        return true;    }    else    {         return false;    }}public void ReplaceGmail(TextBox sender){    sender.Text.Replace("@gmail.com, "@yahoo.com");}這段代碼是我嘗試過(guò)的,所以有什么建議嗎?我還嘗試獲取 @gmail.com 的索引并將其刪除,但它也不起作用
查看完整描述

2 回答

?
慕絲7291255

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

字符串是不可變的,因此String類中的每個(gè)方法都不會(huì)修改當(dāng)前實(shí)例,而是返回一個(gè)新實(shí)例。您必須將其分配給原始變量:

sender.Text?=?sender.Text.Replace("@gmail.com,"@yahoo.com");
查看完整回答
反對(duì) 回復(fù) 2023-08-20
?
拉莫斯之舞

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

像這樣的東西:


//DONE: we should check for null

//DONE: it's Yahoo if it ends on @yahoo.com (not contains)

public static bool IsYahoo(TextBox sender) =>

  sender != null && 

  sender.Text.TrimEnd().EndsWith("@yahoo.com", StringComparison.OrdinalIgnoreCase);


public static bool IsGmail(TextBox sender) =>

  sender != null && 

  sender.Text.TrimEnd().EndsWith("@gmail.com", StringComparison.OrdinalIgnoreCase);


public static void InsertYahoo(TextBox sender) {

  if (null == sender)

    throw new ArgumentNullException(nameof(sender));


  if (IsYahoo(sender))

    return;


  // Uncomment, In case you want to change gmail only

  //if (!IsGmail(sender)) 

  //  return;


  // If we have an eMail like bla-bla-bla@somewhere

  int p = sender.Text.LastIndexOf('@');


  // ... we change somewhere to yahoo.com

  if (p > 0)

    sender.Text = sender.Text.Substring(0, p) + "@yahoo.com";




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

添加回答

舉報(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)