Affichage des articles dont le libellé est C# Words Count. Afficher tous les articles
Affichage des articles dont le libellé est C# Words Count. Afficher tous les articles

C# Count Words In Text File

How To Count The Number Of Words In A .txt File Using C#

Count Words In Text File Using C#

In This C# Tutorial  We Will See How To Get The Number Of Words Inside A Text File Using CSharp Programming Language And Visual Studio Editor.


Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Csharp_Tutorials
{
    public partial class Text_File_Count_Words : Form
    {
        public Text_File_Count_Words()
        {
            InitializeComponent();
        }

        private void buttonCount_Click(object sender, EventArgs e)
        {

            string filePath = textBox1.Text;
            string[] lines = File.ReadAllLines(filePath);

            int count = 0;

            char[] separator = { ' ' };

            for(int i = 0; i < lines.Length - 1; i++)
            {
                count += lines[i].ToString().Split(separator, StringSplitOptions.RemoveEmptyEntries).Length;
            }

            label1.Text = count.ToString();

        }
    }
}




///////////////OUTPUT:

get the number of words in a txt file using c#







C# Words Count

How To Count Words In A String Using Csharp

words count in c#

In This C# Tutorial  We Will See How To Count The Number Of Words In A TextBox Text Using CSharp Programming Language And Visual Studio Editor.


Project Source Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class FormDATA : Form
    {
       
        public FormDATA()
        {
            InitializeComponent();
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string txt = textBox1.Text;

            char[] separator = {' '};

            int wordsCount = txt.Split(separator, StringSplitOptions.RemoveEmptyEntries).Length;

            MessageBox.Show(wordsCount.ToString());
        }
    }
}



///////////////OUTPUT:





number of words using c#