Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Count Characters Including the Break Line of an HTML TAG

I have a regex to remove the html tags to count my characters. Which is working fine.

<string_variable>.replaceAll("<(.|\n)*?>","").replaceAll("&nbsp;"," ").replaceAll("&amp;","&");

alert <string_variavle>.length()

But I need to add the
(New Line) to count my characters.

ABC

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

DEC

For example above ABC and DEC are 6 characters with 2 break lines it should be 9. As of now it is just counting with 6 characters.

Search for similar issue.
Tweaking my code

>Solution :

You can systematically replace all of your \n to a different char and then use the length:

const temp = myVar.replaceAll("\n", "a")
console.log(temp.length)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading