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

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

如何將單詞更改為特定單詞?

如何將單詞更改為特定單詞?

PHP
白衣染霜花 2023-06-24 15:54:48
我需要更改單詞,例如我有一個文本:“你好”我需要將其更改為:“你好”我如何檢測文本是否包含例如字符“h”,然后將其更改為字符“?”?
查看完整描述

2 回答

?
皈依舞

TA貢獻1851條經驗 獲得超3個贊

更換方法:


var str = "hello";


var newStr = str.replace("h", "Y");


console.log(newStr);


查看完整回答
反對 回復 2023-06-24
?
斯蒂芬大帝

TA貢獻1827條經驗 獲得超8個贊

這取決于你真正想要什么。


如果你只想檢測hello你可以使用一個簡單的replace():


let str = 'hello, how are you?'


let newStr = str.replace('hello', '?????')


console.log(newStr) // Output: '?????, how are you?'

如果您只需要檢測第一個字母,h您可以執行相同的操作:


let str = 'hello, how are you?'


let newStr = str.replace('h', '?')


console.log(newStr) // Output: '?ello, how are you?'

但如果你想檢測所有字母,h你必須使用RegExp


let str = 'hello, how are you?'


let newStr = str.replace(/h/g, '?')


console.log(newStr) // Output: '?ello, ?ow are you?'


查看完整回答
反對 回復 2023-06-24
  • 2 回答
  • 0 關注
  • 149 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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