Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace target string is "\" in replace function is different with brower. #25812

Closed
sixther-dc opened this issue Jan 30, 2019 · 6 comments
Closed
Labels
repl Issues and PRs related to the REPL subsystem. util Issues and PRs related to the built-in util module.

Comments

@sixther-dc
Copy link

  • Version:
    v10.15.0

  • Platform:
    Linux moon 3.10.0-862.14.4.el7.x86_64 deps: update openssl to 1.0.1j #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

  • Subsystem:

replace function

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Jan 30, 2019

It is just a different representation of the same string: browser console outputs a simple readable representation as a visible text, Node,js console outputs a source code representation, i.e. what you need to write in the code to get this string. Try in both consoles c === 'duan\x5cchao'.

@sixther-dc
Copy link
Author

It is just a different representation of the same string: browser console outputs a simple readable representation as a visible text, Node,js console outputs a source code representation, i.e. what you need to write in the code to get this string. Try in both consoles c === 'duan\x5cchao'.

Thanks for relpy, I want replace "?" to "".
input: "duan?chao"
output: "duan\chao"

@vsemozhetbyt
Copy link
Contributor

Your code seems valid for this purpose.

@sixther-dc
Copy link
Author

sixther-dc commented Jan 30, 2019

Your code seems valid for this purpose.

no no, It return "duan\\chao" (2"\") in node.js,
I want to return "duan\chao" (1"\") like execute this code in browser.

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Jan 30, 2019

It is just displayed this way in the Node.js console, with escaped backslash. Both results are identical, they have the same length and characters. You can check c.length or c.split('') in both consoles.

@sixther-dc
Copy link
Author

Yeah, I get it, thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

No branches or pull requests

2 participants