【发布时间】:2021-09-27 00:00:27
【问题描述】:
我正在尝试用一定数量的
一个特定的字符(即:"*"),我将在下面的代码中解释更多。
/**
* Returns a string with replaced amount of strings with a set string
* @param {string} str The input
* @param {number} amountToReplace The amount of letters you want to replace
* @param {string} generalReplace The general letter to replace with
* @returns {string} Returns a string with the string thats finished
*/
var str = 'thisisastring';
var amountToReplace = 5;
var generalReplace = '*'
// Function over here, e.g. with the name replacer
var returnMe = replacer(str, amountToReplac
对不起,如果参数听起来令人困惑,我对他们还是新手!
所以字符串,str 是输入字符串,amountToReplace 是您要替换的字母数量,generalReplace 是您要替换的通用字符。
如果金额是5,我期望的输出是这样的:
原文: thisisastring
输出: th*s**as*ri*g
返回的字符串应该替换字符串中的随机部分(但仍然做输入的数量,而不是做 5 个替换,而是返回 3 个作为常见匹配项)。
谢谢!
【问题讨论】:
-
您要随机替换吗?
-
是的,还有我想替换的一组字符串
标签: javascript string replace