//将value从逗号分隔的字符串中删除
//比如从a,b,c,d 将c删除,得到a,b,d
function removeFromCommaJoinedText(value, container) {
if (value.length == 0)
return '';
//去除前后逗号
value = value.replace(/^,/, '').replace(/,$/, '');
container = container.replace(/^,/, '').replace(/,$/, '');
if (container == value)
{
return '';
}
var sArray = container.split(',');
for (var i = sArray.length - 1; i >= 0; --i)
{
if (sArray[i] == value)
sArray[i] = undefined;
}
var result = sArray.join(',');
//因为undefined会连接成,,所以要将,,换成,
result = result.replace(/,,/,',');
result = result.replace(/^,/, '').replace(/,$/, '');
return result;
}
从逗号分隔的字符串中删除某个子串的js函数
最新推荐文章于 2022-09-27 10:40:25 发布