无涯教程-JavaScript - REPLACE函数

44 阅读1分钟

描述

REPLACE函数根据您指定的字符数,用不同的文本字符串替换文本字符串的一部分。

REPLACEB根据您指定的字节数,用不同的文本字符串替换文本字符串的一部分。

REPLACE适用于使用单字节字符集(SBCS)的语言,而REPLACEB适用于使用双字节字符集(DBCS)的语言。您计算机上的默认语言设置会影响返回值,如下所示:

  • REPLACE始终将每个字符(无论是单字节还是双字节)都计为1,无论默认语言设置是什么。

  • REPLACEB在启用对支持DBCS的语言的编辑并将其设置为默认语言后,会将每个双字节字符计数为2。否则,REPLACEB将每个字符计数为1。

支持DBCS的语言包括日语,中文(简体),中文(繁体)和韩语。

语法

REPLACE (old_text, start_num, num_chars, new_text) 
REPLACEB (old_text, start_num, num_bytes, new_text)

争论

Argument 描述 Required/Optional
Old_text Text in which you want to replace some characters. Required
Start_num The position of the character in old_text that you want to replace with new_text. Required
Num_chars The number of characters in old_text that you want REPLACE to replace with new_text. Required
Num_bytes The number of bytes in old_text that you want REPLACEB to replace with new_text. Required
New_text The text that will replace characters in old_text. Required

Notes

如果start_num或num_chars为负数或非数字,则REPLACE返回#VALUE!错误值。

适用性

Excel 2007,Excel 2010,Excel 2013,Excel 2016

Example

REPLACE Function

参考链接

www.learnfk.com/javascript/…