Tuesday, 3 August 2010

Calculating the Length of a String

Simple little one again for a Tuesday afternoon. A quick little demonstration on how to calculate the length of a string :

in c#

string test_string;
int value;
test_string = "George";
value = test_string.Length;
length.Text = value.ToString();

and also in vb.net

Dim test_string As String
Dim value As Integer
test_string = "George"
value = Len(test_string)
length.Text = value

and finally in PHP:

$howlong="how long is my string including spaces";
echo "The length of the string is : ".strlen($howlong);

No comments:

Post a Comment