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 comments so far

  1. drj11 on

    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. michiel on

    Thanks. Not only was I bored, also confused 😉

  3. […] find out if a variable has been defined Posted by michiel under Programming   It’s two articles now, it must be a series! Here’s how to find the out if a variable has been defined […]

  4. […] Programming, Uncategorized | Tags: programming php javascript |   It’s three articles (1 2) now, it’s almost a book! Here’s how to create a class in my three favorite […]

  5. Slava on

    If a string is Unicoded, how many bytes does string fit?
    Any idea for Javascript solution?

  6. zwembroek on

    Wikia…

    Wika linked to this site…


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

%d bloggers like this: