Home arrow JavaScript arrow Page 3 - Stringing Things Along

When Size Does Matter - JavaScript

Think JavaScript's only good for image swaps and tickertapes?Think again - the language comes with a powerful String() objectdesigned to help you quickly and efficiently perform string manipulationtasks in the client. This article explains how, with illustrations andcode samples.

  1. Stringing Things Along
  2. Elementary School
  3. When Size Does Matter
  4. Slice And Dice
  5. Building Character
  6. Search And Destroy
  7. Bigger, Bolder, Better
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 10
January 22, 2003

print this article


With the basics out of the way, let's now turn to some of the other string methods and properties available in JavaScript. One of the most common properties you'll find yourself using is the "length" property, which returns the length of a particular string. Consider the following example, which demonstrates:

<script language="Javascript">
// set string
var movie = "Four Weddings And A Funeral";
// print length
alert ("The length of the movie is " + movie.length + " characters");

This property can come in handy for operations which involve processing every character in a string (as you'll see shortly).

The String object also comes with a split() method, which can be used to decompose a single string into separate units on the basis of a particular separator value; these units are then placed into an array for further processing. Consider the following example, which demonstrates:

<script language="Javascript">
// set string
var friends = "Joey, Rachel, Monica, Chandler, Ross, Phoebe";
// split into array using commas
var arr = friends.split(", ");
// iterate through array and print each value
for (x=0; x<arr.length; x++)
alert("Hiya, " + arr[x]);

>>> More JavaScript Articles          >>> More By Harish Kamath, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Javascript for Beginners: An Introduction
- Introduction to JavaScript
- Adding Elements to a Tree with TreeView jQue...
- Using the Persist Argument in a TreeView jQu...
- Using Unique and Toggle in a TreeView jQuery...
- Using Event Delegation for Mouseover Events ...
- Using the Animate Option in a Treeview jQuer...
- Using HTML Lists with Event Delegation in Ja...
- Opened and Closed Branches on a TreeView jQu...
- Mouseover Events and Event Delegation in Jav...
- Creating a TreeView JQuery Hierarchical Navi...
- Event Delegation in JavaScript
- A Look at the New YUI Carousel Control
- Working with Draggable Elements and Transpar...
- Displaying Pinned Handles with Resizable Con...

Developer Shed Affiliates


Dev Shed Tutorial Topics: