First:
var s = input_string.replace(/\t/g, '|');
Second:
var s = input_string.split('\t').join('|');
Is there any possibility that they could get different results?
First:
var s = input_string.replace(/\t/g, '|');
Second:
var s = input_string.split('\t').join('|');
Is there any possibility that they could get different results?
Assuming that input_string
is a plain string, and that none of the build-in methods String.prototype.replace
, String.prototype.split
, Array.prototype.join
have been tampered with - then no, .replace
followed by .join
in that matter will always produce the same output.
If you allow for the possibility that the methods have been patched, then all bets are off.
String.prototype.replace = () => '';
console.log('foo'.replace(/\t/g, '|'));