Home arrow JavaScript arrow Page 6 - Stringing Things Along

Search And Destroy - 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


You can also search for specific patterns in your strings with regular expressions, via the String object's search() method. Here's an example:

<script language="JavaScript">
var str = "johndoe@somedomain.com";
var pattern =
// returns 0

The search() method returns the position of the substring matching the regular expression, or -1 if no match exists.

You can also perform a search-and-replace operation with the replace() method, which accepts both a regular expression and the value to replace it with. Here's how:

<script language="JavaScript">
// set string
var str = "yo ho ho and a bottle of gum";
// returns "yo ho ho and a bottle of rum" alert(str.replace(/gum/gi,

>>> 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: