jsÔõôɾ³ý×Ö·û´®ÖеÄÖ¸¶¨×Ö·û
ÓÐËÄÖÖÒªÁì¿ÉÒÔɾ³ý×Ö·û´®ÖеÄÖ¸¶¨×Ö·û£ºÊ¹Óà string.replace()£¬½«Ìæ»»×Ö·û´®Áô¿Õ¡£Ê¹ÓÃÕýÔò±í´ïʽ£¬Ìí¼Ó g ±ê¼Ç²¢Ö¸¶¨ÒªÉ¾³ýµÄ×Ö·û¡£½«×Ö·û´®²ð·ÖΪÊý×飬ɾ³ý×Ö·ûºóÖØÐÂÅþÁ¬¡£Ê¹ÓÃÑ»·±éÀú×Ö·û´®£¬Ìø¹ýҪɾ³ýµÄ×Ö·û¡£
ÔõÑùÔÚ JavaScript ÖÐɾ³ý×Ö·û´®ÖеÄÖ¸¶¨×Ö·û
ÔÚ JavaScript ÖУ¬Óм¸ÖÖÒªÁì¿ÉÒÔɾ³ý×Ö·û´®ÖеÄÖ¸¶¨×Ö·û¡£
ÒªÁìÒ»£ºString.replace()
¸ÃÒªÁìÎüÊÕÁ½¸ö²ÎÊý£ºÒª²éÕÒµÄ×Ö·û£¨»òÕýÔò±í´ïʽ£©ºÍÒ»¸öÌæ»»×Ö·û´®¡£ÈôÊÇҪɾ³ý×Ö·û£¬Ôò½«Ìæ»»×Ö·û´®Áô¿Õ¡£
const str = "Hello, world!"; const newStr = str.replace('l', ''); // "Heo, word!"
µÇ¼ºó¸´ÖÆ
ÒªÁì¶þ£ºÕýÔò±í´ïʽ
ÕýÔò±í´ïʽÊÇÒ»ÖÖÓÃÓÚÆ¥Åä×Ö·û´®ÖÐģʽµÄÇ¿Ê¢ÓïÑÔ¡£ÒªÉ¾³ý×Ö·û£¬¿ÉÒÔʹÓà g ±ê¼Ç£¬ÌåÏÖÈ«¾ÖÆ¥Å䣬²¢Ö¸¶¨ÒªÉ¾³ýµÄ×Ö·û¡£
const str = "Hello, world!"; const newStr = str.replace(/[l]/g, ''); // "Heo, word!"
µÇ¼ºó¸´ÖÆ
ÒªÁìÈý£º×Ö·û´®²ð·ÖºÍÅþÁ¬
´ËÒªÁìÉæ¼°½«×Ö·û´®²ð·ÖΪһ¸öÊý×飬ɾ³ýËùÐèµÄ×Ö·û£¬È»ºóÖØÐÂÅþÁ¬Êý×éÖеÄ×Ö·û¡£
const str = "Hello, world!"; const newStr = str.split('l').join(''); // "Heo, word!"
µÇ¼ºó¸´ÖÆ
ÒªÁìËÄ£ºÊ¹ÓÃÑ»·
ʹÓÃÑ»·±éÀú×Ö·û´®£¬²¢Ìø¹ýҪɾ³ýµÄ×Ö·û¡£
const str = "Hello, world!"; let newStr = ""; for (let i = 0; i
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇjsÔõôɾ³ý×Ö·û´®ÖеÄÖ¸¶¨×Ö·ûµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡