Find Length / Count Number of characters in sentence (String) using C# and VB.Net

smile
 
on Jun 05, 2018 04:56 AM
Sample_170594.zip
2810 Views

The Quick brown fox jumps over the lazy dog.

I want to count character length till "The Quick Brown"  and then want to print output like this

Total Characters Count : 15

how to do it in asp.net

Download FREE API for Word, Excel and PDF in ASP.Net: Download
mukesh1
 
on Jun 05, 2018 05:03 AM
on Jun 05, 2018 05:04 AM

 string s="The Quick Brown";

Total Characters Count :s.length();

 

use string builder class in namespace of page

pandeyism
 
on Jun 05, 2018 05:12 AM

Hi smile,

Please take reference to below code and correct your code.

HTML

<asp:Label ID="lblStatement" runat="server"></asp:Label>

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    string strStatement = "The Quick Brown";
    lblStatement.Text = "Total Characters Count : " + strStatement.Length.ToString();
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim strStatement As String = "The Quick Brown"
    lblStatement.Text = "Total Characters Count : " & strStatement.Length.ToString()
End Sub

Output

Total Characters Count : 15