Affichage des articles dont le libellé est string. Afficher tous les articles
Affichage des articles dont le libellé est string. Afficher tous les articles

Javascript String Occurrence In A String

How To Count SubString Occurrence In A String Using Javascript 

String Count Occurrence Inside A String Using Javascript


In this Javascript tutorial, we will learn how to count the number of occurrences of a specific string within a text using the substring() function and a for loop in Javascript
We will also use the NetBeans editor for coding.



Project Source Code:

    
<!DOCTYPE html>
<html>
    <head>
        <title>Javascript: string occurrence</title>
        <meta charset="windows-1252">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <p>js stringjs occurjsrence in a jsstring</p>
        <script>
            
            var txt = "js stringjs occurjsrence in a jsstring",
                valToFind = "string",
                count = 0;
            
            for(var i = 0; i < txt.length; i++){
                
                console.log(txt.substring(i, i+valToFind.length));
                //              (start, end)
                if(txt.substring(i, i+valToFind.length) === valToFind){
                    count++;
                }
                
            }
            console.log(count);
        </script>
        
        
    </body>
</html>




OUTPUT: 2

Java Words Count

How To Count Words In A String Using Java Netbeans

words count in java

In This Java Tutorial  We Will See How To Count The Number Of Words In A jTextField Text Using Java Programming Language And NetBeans Editor.

STEPS:
1 - the user enter text into the jtexfields
2 - the user click "count" button to display the number of words in the text.


Project Source Code:

private void jButtonCountActionPerformed(java.awt.event.ActionEvent evt) {                                             
        
        String txt = jTextField1.getText();
        String[] words = txt.split(Pattern.quote(" "));
        System.out.println(words.length);
        
    } 


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

number of words in a string using java
Result : 11


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>



C# - How to make a textbox that only accepts numbers or only characters

C# - How to make a textbox that only accepts numbers or only characters

                                                                                                                                                           

in this c# tutorial we will see how to make a textbox that only accepts numbers or only characters in C# .


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 TextBox_Numbers_Characters : Form
    {
        public TextBox_Numbers_Characters()
        {
            InitializeComponent();
        }

        private void TXTB_ONLY_CHAR_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void TXTB_ONLY_NUMBER_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void TXTB_CHAR_AND_NUMBER_KeyPress(object sender, KeyPressEventArgs e)
        {
            // allow digit + char + white space
            if (!char.IsControl(e.KeyChar) && !char.IsLetterOrDigit(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))
            {
                e.Handled = true;
            }
        }

    }
}


=> OutPut :

Textbox Accepts Only Numbers Or Only Characters
Textbox Accepts Only Numbers Or Only Characters In C#