How to find the length of a string

Just out of being bored I decided to share some really basic source code. Here’s how to find the lenght of a text in my three favorite languages:

PHP

$s = "simple php programming";
$length = strlen($s);

JavaScript

var s = "simple javascript programming";
var length = s.length;

(Visual) Basic

dim s as string
dim length as integer

s = "simple basic programming";
length = len(s);
Advertisements

6 thoughts on “How to find the length of a string

  1. The JavaScript version has a trivial bug. It should be «var length = s.length». length is a straightforward property, not a method to be invoked.

  2. Pingback: zwembroek

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s