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#



C# Populate DataGridView Using Multidimensional Array

How To Fill DataGridView From 2D Array Data Using C#

Fill DataGridView From Multidimensional Array Content Using C#


In This C# Tutorial  We Will See How To Populate A DataGridView From A Multidimensional Array Content Using For Loop In 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 _2DArray_To_DataGridView : Form
    {
        public _2DArray_To_DataGridView()
        {
            InitializeComponent();
        }

        private void _2DArray_To_DataGridView_Load(object sender, EventArgs e)
        {
            string[,] rows = new string[,]{ // 1   2     3     4 
                                             {"1","AAA","BBB","10"},//1
                                             {"2","CCC","DDD","20"},//2
                                             {"3","ZZZ","YYY","30"},//3
                                             {"4","LLL","MMM","40"},
                                             {"5","NNN","TTT","50"},
                                             {"6","WWW","RRR","60"},
                                             {"7","GGG","PPP","70"}//7
                                          };

            // rows.GetLength(0) return length of the first D (7)
            // rows.GetLength(1) return length of the second D
            for(int i = 0; i < rows.GetLength(0); i++)// array rows
            {
                string[] row = new string[rows.GetLength(1)];

                for(int j = 0; j < rows.GetLength(1); j++)
                {
                    row[j] = rows[i, j];
                }

                dataGridView1.Rows.Add(row);
            }
        }
    }
}


// OUTPUT :

2D array to datagridview in c#



C# Search In A Multidimensional Array

How To Find Value In A 2D Array Using C#

Find Value Position In A Multidimensional Array Using C#



In this C# Tutorial we will see How To Search And Find A Value Position Inside A  Multidimensional Array Using For Loop + TextBox And Display The Positions Inside A RichTextBox On A Button Click Event In 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 Search_In_2D_Array : Form
    {
        public Search_In_2D_Array()
        {
            InitializeComponent();
        }

        // create 2D array
        string[,] data;
        private void Search_In_2D_Array_Load(object sender, EventArgs e)
        {
            // add data to the array
            data = new string[,]{// 1    2     3    4
                                  {"1","AAA","BBB","10"},//1
                                  {"2","CCC","DDD","20"},//2
                                  {"3","ZZZ","YYY","30"},//3
                                  {"4","LLL","CCC","40"},
                                  {"5","NNN","TTT","50"},
                                  {"6","CCC","RRR","CCC"},
                                  {"7","GGG","CCC","70"}//7
                                };

            // display array data into richTextbox
            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    richTextBox1.Text += data[i, j] + " - ";
                }

                richTextBox1.Text += "\n";
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox2.Text = "";
            // data.GetLength(0) = length of the first D (7)
            for(int i = 0; i < data.GetLength(0); i++)
            {
                // data.GetLength(1) = length of the second D (4)
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    if(textBox1.Text.Equals(data[i,j]))
                    {
                        richTextBox2.Text += "POSITION[" + i + " , " + j + "]";
                    }
                }
            }

        }

        
    }
}


OutPut:

search in 2D array using c#



VB.Net Populate Combobox From Datatable

How To Fill A Combobox Using A DataTable In Visual Basic.Net 

Populate Combobox From Datatable Using VB.Net

In This VB.Net Tutorial  We Will See How To Populate A ComboBox From DataTable In Form Load Using Visual Basic.Net Programming Language And Visual Studio Editor.


Project Source Code:

Public Class PopulateComboboxFromDatatable

    Private Sub PopulateComboboxFromDatatable_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim table As New DataTable()
        table.Columns.Add("id")
        table.Columns.Add("username")

        table.Rows.Add("1", "UN1")
        table.Rows.Add("2", "UN2")
        table.Rows.Add("3", "UN3")
        table.Rows.Add("4", "UN4")
        table.Rows.Add("5", "UN5")
        table.Rows.Add("6", "UN6")

        ComboBox1.DataSource = table
        ComboBox1.DisplayMember = "username"

    End Sub
End Class
      
///////////////OUTPUT:





filling combobx from datatable in vb.net




VB.Net Add ITem To ComboBox

How To Add Value To A Combobox Using Visual Basic.Net 

vbnet add items to combobox

In This VB.Net Tutorial  We Will See How To Insert Values To ComboBox From TextBox Or Another ComboBox On Button Click In Visual Basic.Net Programming Language And Visual Studio Editor.


Project Source Code:

Public Class AddValueToCombobox

    Private Sub BTN_ADDVal_Click(sender As Object, e As EventArgs) Handles BTN_ADDVal.Click

       ' add value from textbox
        ComboBox1.Items.Add(TextBox1.Text)
       ' add value from textbox in specific index
        ComboBox1.Items.Insert(0, TextBox1.Text)
        ' add value from another combobox
        ComboBox1.Items.Add(ComboBox2.SelectedItem)

    End Sub
End Class
      
///////////////OUTPUT:





add item to combobox using vb.net




Javascript Remove First Or Last Character In A String

How To Delete A Char From The Start Or The End Of A String Using Javascript  

delete a character from the start or the end of a string using javascript


In This Javascript Tutorial we will See How To Delete The Char At The Beginning Of A String Or At The End On Button Click Event In JS And Netbeans Editor .


Project Source Code:

    
<!DOCTYPE html>
<html>
    <head>
        <title>Javascript: Clear Char</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        
        <p id="pText">0123456789</p>
        <button onclick="clearChar()">clear</button>
        
        <script>
            
            function clearChar(){
                
                var pt = document.getElementById("pText");
                // remove char from the beginning
                pt.innerHTML = pt.innerHTML.substring(1,pt.innerHTML.length);
                //
                // remove char from the end
                pt.innerHTML = pt.innerHTML.substring(0,pt.innerHTML.length-1);
                
            }
            
        </script>    
    </body>
</html>



Java Add, Edit, Remove JTree Node

How To Insert Update Delete Selected Node From JTree Using Java NetBeans

Insert Update Delete JTree Node



In this Java Tutorial we will see How To Add Edit Remove The Selected JTree Node Using DefaultMutableTreeNode + DefaultMutableTreeNode + TreeSelectionModel + The JTextFields Value On JTree Mouse Clicked Event To Get The Selected Node And 3 Button To Do The Insert, Update, Delete In Java Programming Language And NetBeans IDE .




Project Source Code:

private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {                                    
        // Display Selected Node Text Into JTextFields
        
        TreeSelectionModel smd = jTree1.getSelectionModel();
        if(smd.getSelectionCount() > 0){
            DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
            jTextField1.setText(selectedNode.getUserObject().toString());
        }
    }                                   

    private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) {                                           
        
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(jTextField1.getText());
        selectedNode.add(newNode);
        
        // reload jtree model
        DefaultTreeModel model = (DefaultTreeModel)jTree1.getModel();
        model.reload();
    }                                          

    private void jButtonEditActionPerformed(java.awt.event.ActionEvent evt) {                                            
       
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        
        selectedNode.setUserObject(jTextField1.getText());
        // reload jtree model
        DefaultTreeModel model = (DefaultTreeModel)jTree1.getModel();
        model.reload();
        
    }                                           

    private void jButtonEdit1ActionPerformed(java.awt.event.ActionEvent evt) {                                             
        
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();
        
        if(selectedNode != jTree1.getModel().getRoot())
        {
            DefaultTreeModel model = (DefaultTreeModel)jTree1.getModel();

            model.removeNodeFromParent(selectedNode);

            model.reload();
        }
    } 

OutPut:

jtree selected node add, edit, delete using java