xxx.subString is not a function?

        I encountered this error when working on a project recently. The effect I want to achieve is to hide the middle part of a long string of strings, for example, the following effect:

         Needless to say, you all know how to do it. Then I will also say my thoughts:

1.var str = string to hide

2.var temp = str.subString(start,end)

3.str = str.replace(new Rexp(temp),"****");

        The above steps are correct, but this error is reported on the console. I am really baffled. I have been checking the information and can’t find the problem. I thought that str is not a string type. After typeof, it is also a string type, and then Suddenly replacing subString with slice is just fine, and the effect of the two is the same.

        So it should be noted that if you also encounter this error and are at a loss, you might as well try to replace subString with slice, maybe it will take effect.

        Another thing to mention is that if the first parameter of replace is regular, then the specific string that needs to be matched must be used in the regular, and variables cannot be written. If the regular accepts a variable like the above, it needs to be created by using Rexp. A regular object, which is then used to accept a variable.

Guess you like

Origin blog.csdn.net/qq_41083105/article/details/118796642