• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

Count Number of Characters using C#

adolfm

NFT Marketplace Expert
A Rep
0
0
0
Rep
0
A Vouches
0
0
0
Vouches
0
Posts
168
Likes
57
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
Today in C# tutorial, i will teach you how to create a program that counts the number of characters using C#.

Now, let's start this tutorial!

1. Let's start with creating a Windows Form Application in C# for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application and name your project as Count Number of Characters.

2. Next, add only one Button named Button1 and labeled it as "Count Characters". Add also TextBox named TextBox1 for our input. You must design your interface like this:

countdesign.png


3.Now put this code for your code module. This code is for Button1_Click that will trigger to count the number of characters in your textbox.

We will have to initialize first a variable that will hold the value/string inputted in our textbox and we will name it strLength as a String variable that will hold the inputted text of textbox1.
  1. string

    strLength =

    TextBox1.

    Text

    ;

Then we will have to create a messagebox that will display the total number of characters in the inputted textbox. The strLength variable with its length it returns the count of attributes for an element of the textbox. We will have the ToString method also that converts the length of the textbox to its string representation so that it is suitable for display.
  1. MessageBox.

    Show

    (

    "Number of Characters: "

    +

    strLength.

    Length

    .

    ToString

    (

    )

    )

    ;

Full source code:

  1. using

    System.Diagnostics

    ;
  2. using

    System

    ;
  3. using

    System.Windows.Forms

    ;
  4. using

    System.Collections

    ;
  5. using

    System.Drawing

    ;
  6. using

    Microsoft.VisualBasic

    ;
  7. using

    System.Data

    ;
  8. using

    System.Collections.Generic

    ;


  9. namespace

    Count_Number_of_Characters
  10. {
  11. public

    partial

    class

    Form1
  12. {
  13. public

    Form1(

    )
  14. {
  15. InitializeComponent(

    )

    ;


  16. if

    (

    defaultInstance ==

    null

    )
  17. defaultInstance =

    this

    ;
  18. }


  19. public

    void

    Button1_Click(

    System

    .

    Object

    sender, System

    .

    EventArgs

    e)
  20. {
  21. string

    strLength =

    TextBox1.

    Text

    ;
  22. MessageBox.

    Show

    (

    "Number of Characters: "

    +

    strLength.

    Length

    .

    ToString

    (

    )

    )

    ;
  23. }
  24. }

  25. }

Output:
countout.png


Download the source code below and try it! :)

Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer

If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,499

349,924

349,934

Top