Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将单词更改为特定单词?_Javascript_Php - Fatal编程技术网

Javascript 如何将单词更改为特定单词?

Javascript 如何将单词更改为特定单词?,javascript,php,Javascript,Php,我需要更改单词,例如我有一个文本: “你好” 我需要把它改成: "ჰელლო" 如何检测文本是否包含例如char“h”,然后将其更改为char“ჰ“?替换方法: var str=“你好”; var newStr=str.replace(“h”,“Y”); console.log(newStr);这取决于您真正想要什么 如果只想检测hello,可以使用一个简单的replace(): 如果只需要检测第一个字母h,您也可以这样做: let str = 'hello, how are you?' l

我需要更改单词,例如我有一个文本:

“你好”

我需要把它改成:

"ჰელლო"

如何检测文本是否包含例如char“h”,然后将其更改为char“ჰ“?

替换方法:

var str=“你好”;
var newStr=str.replace(“h”,“Y”);

console.log(newStr);
这取决于您真正想要什么

如果只想检测
hello
,可以使用一个简单的
replace()

如果只需要检测第一个字母
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?'

我想你在找类似的东西
let str = 'hello, how are you?'

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

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