How to count the words in a String in C#

Remember the Word Count function in Microsoft Word? Here’s how we could implement counting the words in a String in C#:

The following is the spource code of a program featuring two word counting methods, both of which yield fairly similar results to Microsoft Word from Microsoft Office 2007. The example program below first executes a Regex-based function for counting the words in the string constant, and then executes the loop-based one.

Read more

Example with Source Code: A simple database-driven Java web application (CRUD) implementing JSP and Servlets

You can study and implement the following examples to create a simple Java-based database-driven web application which makes use of JSP and Servlets applying a MVC (model-view-controller) principle.

Create the following files:

package sample;
import java.sql.*;

public class DatabaseConnection {

    public static Connection getConnection() {
    Connection con = null;
    try {
        // change the following line to your jdbc driver
        // change this to "your database url", "username", "password"
        con = DriverManager.getConnection("jdbc:borland:dslocal:C:\\a.jds","Sample","");
        catch (Exception ex) {
    return con;

Read more