<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Md Babul Akter on Medium]]></title>
        <description><![CDATA[Stories by Md Babul Akter on Medium]]></description>
        <link>https://medium.com/@babulakterfsd?source=rss-81d84f47f68a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jF_q-YFBqgs8qqTN6seMog.jpeg</url>
            <title>Stories by Md Babul Akter on Medium</title>
            <link>https://medium.com/@babulakterfsd?source=rss-81d84f47f68a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:04:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@babulakterfsd/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to count words in a string in Javascript?]]></title>
            <link>https://medium.com/babulakterfsd/how-to-count-words-in-a-string-in-javascript-74768db6db99?source=rss-81d84f47f68a------2</link>
            <guid isPermaLink="false">https://medium.com/p/74768db6db99</guid>
            <dc:creator><![CDATA[Md Babul Akter]]></dc:creator>
            <pubDate>Thu, 30 Jul 2020 09:28:25 GMT</pubDate>
            <atom:updated>2020-07-30T09:28:25.305Z</atom:updated>
            <content:encoded><![CDATA[<p>How to count words in a string in Javascript?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oZbuCApAXDvZaHcuUtCl5A.png" /></figure><p>Well, are you finding a solution for this problem? ok, let’s do it in practice, I like to do things, not to talk, hahaha. Literally, we can have strings including spaces, colons, numbers, letters, or whatever and that is the problem when we start creating a function using RegExp. But in here, I’ve solved it and commented everything as you can get the motive of the lines easily.</p><p>let mystr = ` I’m the king 007 ! `; // string whose words are going to be counted (21)</p><p>function countWords(str) {</p><p>let totalLength = str.length; //length of the string(how many characters are there)</p><p>let onlyLetterAndNumbers = str.replace(/[^a-zA-Z0–9]*/gi, ``).length; //counts all the letters and numbers only</p><p>let nonLetterAndNumbers = totalLength — onlyLetterAndNumbers; // substract all the letters and numbers from total length and get non letters length</p><p>if (onlyLetterAndNumbers != 0) { // if there is letter or numbers in the string this will be executed</p><p>return nonLetterAndNumbers + str.match(/[\w]+/g).length;</p><p>} else { // if there is letter or numbers in the string this will be executed</p><p>return nonLetterAndNumbers;</p><p>}</p><p>}</p><p>console.log(countWords(mystr)); // final result</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74768db6db99" width="1" height="1" alt=""><hr><p><a href="https://medium.com/babulakterfsd/how-to-count-words-in-a-string-in-javascript-74768db6db99">How to count words in a string in Javascript?</a> was originally published in <a href="https://medium.com/babulakterfsd">Babulakterfsd</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to count words in a string in javascript?]]></title>
            <link>https://medium.com/@babulakterfsd/how-to-count-words-in-a-string-in-javascript-4da5b32cd45a?source=rss-81d84f47f68a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4da5b32cd45a</guid>
            <dc:creator><![CDATA[Md Babul Akter]]></dc:creator>
            <pubDate>Thu, 30 Jul 2020 09:07:32 GMT</pubDate>
            <atom:updated>2020-07-30T09:07:32.118Z</atom:updated>
            <content:encoded><![CDATA[<p>How to count words in a string in javascript?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4da5b32cd45a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>