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

Last Reply 9 months ago By pandeyism

Posted 9 months ago

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

Posted 9 months ago Modified on 9 months ago

 string s="The Quick Brown";

Total Characters Count :s.length();

 

use string builder class in namespace of page


Posted 9 months ago

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