0

I am trying to search the presence of a substring in another string in ES6, which fails even though the target string contains the search text.

After inspecting the string in devtools, I found a small new-line like character in the string which was breaking my search. You can see it in the screenshot before the word today. However, it doesn't show up in the browser (the image just above the devtools), I am not sure where it's coming from.

What is this character, and how do I strip it out from my string?

(I am sure this is a duplicate question, but I just don't know what to search for, so if anyone can point out to the duplicate question, I'd be more than happy to close this one.)

2
  • Unless the element is <pre> or has style="white-space: pre", the browser wraps lines when it renders text, so you can't see where the newlines were in the original text. Commented Nov 11, 2019 at 20:35
  • Ahh, I see. I wrapped my text in <pre> tag and that shows there was a linebreak in the original string. What is that character called, and how do I get rid of it so my search can work? Commented Nov 11, 2019 at 20:39

1 Answer 1

1

This is how Google Chrome displays an otherwise non-printable sequence of characters in the developer console. In this case, the sequence of characters is a Carriage Return (CR) + Line Feed (LF). The CR moves the cursor to the beginning of the line and the LF moves the cursor one line forward. This simply signifies a string that contains a newline.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I replaced all the newline characters from the string using the expression s.replace(/[\n\r]/g, '') and it got my search working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.