VB.Net Count Character Occurrence

How To Count Specific Character Occurrence In A String Using Visual Basic.Net 

vb.net specific char count

In This VB.Net Tutorial  We Will See How To Count The Number Of Selected Char Occurrences In A TextBox Text Using Visual Basic.Net Programming Language And Visual Studio Editor.


Project Source Code:

Public Class FormCharOccurrence

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim txt As String
        txt = TextBox1.Text

        Dim occurrence As Integer
        occurrence = 0

        For i As Integer = 0 To txt.Length - 1

            If txt(i) = TextBox2.Text.ToCharArray()(0) Then

                occurrence += 1

            End If

        Next

        MsgBox(occurrence)

    End Sub
End Class


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





vb/net count char occurrences



VB.Net Words Count

How To Count Words In A String Using Visual Basic.Net 

words count in vb.net

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


Project Source Code:

Public Class VbWordsCount

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim txt As String
        txt = TextBox1.Text

        Dim separ() As Char = {" "}

        Dim count As Integer

        count = txt.Split(separ, StringSplitOptions.RemoveEmptyEntries).Length

        MsgBox(count.ToString())



    End Sub
End Class


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





get string words count using vb.net



VB.Net TextBox Allow Only Alphabet

How To Make A TextBox Accept Only Alphabet Values Using Visual Basic.Net

vb.net textbox allow only alphabet


In This VB.Net Tutorial we will See How To Make A TextBox That Allow Only Letter Characters + White Space On KeyPress Event using Visual Basic.Net Programming Language And Visual Studio IDE .


Project Source Code:


Public Class TextBox_Only_Alphabet


    Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress

        If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsLetter(e.KeyChar) AndAlso Not Char.IsWhiteSpace(e.KeyChar) Then

            e.Handled = True

        End If

    End Sub
End Class




OUTPUT:



textbox allow only characters using vbnet



Java Count Words In Text File

How To Count Words Inside A Txt File Using Java NetBeans

Count Words In Text File Using Java



In this Java Tutorial we will see How To Get The Number Of Words In A Text File Using For Loop + BufferedReader In Java NetBeans .




Project Source Code:

private void jButtonWordCountActionPerformed(java.awt.event.ActionEvent evt) {                                                 
       
        String filePath = "C:\\Users\\omar\\Desktop\\file2.txt";
        File file = new File(filePath);
        
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            Object[] lines = br.lines().toArray();
            
            int wordCount = 0;
            
            for(int i = 0; i < lines.length; i++){
                String[] words = lines[i].toString().split(Pattern.quote(" "));
                // get word count line by line
                wordCount += words.length;
               }
             System.out.println(wordCount);
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(java_text_words_count.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    } 


VB.Net Using Regex

How To Use Regular Expressions In Visual Basic .Net

Using Regular Expressions In Visual Basic .Net



In this VB.NET Tutorial we will see How To Use Regular Expression To Verfiy Email Address, Phone Number, Website URL On A Button Click Event In Visual Basic.Net Programming Language And Visual  Studio Editor.




Project Source Code:


Imports System.Text.RegularExpressions

Public Class Regular_Expression

    Private Sub ButtonVerify_Click(sender As Object, e As EventArgs) Handles ButtonVerify.Click


        ' mail@mail.com                          =>  ^([\w]+)@([\w]+)\.([\w]+)$
        ' http(s)://www.google.com               =>  ^((http|https)://www\.)([\w]+)\.([\w]+)$
        ' Phone Number Like : 0011 *** *** ***   =>  ^(0011)(([  ][0-9]{3}){3})$

        execReg("^([\w]+)@([\w]+)\.([\w]+)$", TextBoxEmail, LabelEmail)
        execReg("^(0011)(([  ][0-9]{3}){3})$", TextBoxPhone, LabelPhone)
        execReg("^((http|https)://www\.)([\w]+)\.([\w]+)$", TextBoxWebsite, LabelSite)

    End Sub


    Sub execReg(ByVal pattern As String, ByVal tbx As TextBox, ByVal lbl As Label)

        Dim rgx As New Regex(pattern)

        If rgx.IsMatch(tbx.Text) Then

            lbl.Text = "Valid"
            lbl.ForeColor = Color.Green

        Else

            lbl.Text = "InValid"
            lbl.ForeColor = Color.Red

        End If

    End Sub

End Class


OutPut:

Visula Basic .Net Regular Expressions




Java Remove String First Or Last Char

How To Delete String First / Last Character Using Java NetBeans

delete first or last character using java



In this Java Tutorial we will see How To Delete The Char At The beginning Or The End Of A JTextFields Text ,On Jbutton Click Event The Program Will Remove Text Letter By Letter In Java NetBeans .




Project Source Code:


// remove first character
private void jButtonRFActionPerformed(java.awt.event.ActionEvent evt) {                                          
       
        if(jTextField1.getText().length() > 0)
        {
         String txtMinusFirstChar = jTextField1.getText().substring(1, jTextField1.getText().length());
         jTextField1.setText(txtMinusFirstChar);    
        }
        
        
    }                                         

// remove last character
    private void jButtonRLActionPerformed(java.awt.event.ActionEvent evt) {                                          
      
        if(jTextField1.getText().length() > 0)
        {
         String txtMinusLastChar = jTextField1.getText().substring(0, jTextField1.getText().length() - 1);
         jTextField1.setText(txtMinusLastChar);    
        }
        
    }                                         


// remove first & last character
    private void jButtonRFLActionPerformed(java.awt.event.ActionEvent evt) {                                           
       
        if(jTextField1.getText().length() > 1)
        {
         String txtMinusLFChar = jTextField1.getText().substring(1, jTextField1.getText().length() - 1);
         jTextField1.setText(txtMinusLFChar);    
        }else{
            jTextField1.setText("");
        }
        
    } 


OutPut:

java delete first & last char



Java Create, Write, Delete Text File

How To Create And Write And Delete Txt File Using Java NetBeans

java create writr remove text file



In this Java tutorial will demonstrate how to create a text file with a custom name and write data from a jTextArea into the file. Additionally, we will learn how to remove the file using the FileWriter and BufferedWriter classes in Java NetBeans, all in a step-by-step manner .




Project Source Code:


// create and write in text file
private void jButtonCreateAndWriteActionPerformed(java.awt.event.ActionEvent evt) {                                                      
      
        String filePath = jTextFieldFilePath.getText();
        
        File file = new File(filePath);
        
        if(!file.exists()){
            try {
                
                file.createNewFile();
                FileWriter wr = new FileWriter(file);
                BufferedWriter bw = new BufferedWriter(wr);
                
                bw.write(jTextArea1.getText());
                
                bw.close();
                wr.close();
                
            } catch (IOException ex) {
                Logger.getLogger(TxtFile_Create_Write_Delete.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
    }                                                     

   // delete file
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
        String filePath = jTextFieldFilePath.getText();
        
        File file = new File(filePath);
        
        if(file.exists()){
            file.delete();
        }
        
    } 


OutPut:

create write delete text file using java