|
| previous<
9
10 11
12
13
14
15 16
17
> Next |
|
Regular expressions is a form of pattern matching that you can apply on textual content. Take for example the DOS wildcards ? and * which you can use when you're searching for a file. That is a kind of very limited subset of RegExp. For instance, if you want to find all files beginning with "fn", followed by 1 to 4 random characters, and ending with "ht.txt", you can't do that with the usual DOS wildcards. RegExp, on the other hand, could handle that and much more complicated patterns.
Regular expressions are, in short, a way to effectively handle data, search and replace strings, and provide extended string handling. Often a regular expression can in itself provide string handling that other functionalities such as the built-in string methods and properties can only do if you use them in a complicated function or loop.
|
|
|
|
To get started with advanced string handling in JavaScript, we will begin by looking at two of the JavaScript methods for strings. These two methods, charAt and indexOf, are used to find out what character is at a certain position in a string and to find out where a character or a smaller string begins within a string, respectively. Before we get to those, we will also want to look at the length method. This gives us the length of a string, which may be helpful when we use the other methods. So, let's go in and take a look at these methods, starting with length
|
|
|
|
If you want to assign a value to a position in an array, you can just do this:
Array[9] = "Hello World"
To display the value, just access its index number again:
alert(Array[9])
The fact that you can access the index number of an array to assign values makes them very handy in loops. To start our lottery number generator (UK lottery), we're going to create an array of 49 numbers. Number 1 will be at position 1 in the array, number 2 at position 2, etc. We could do this for all 49 numbers:
|
|
|
|
In this tutorial we'll look at JavaScript's setTimeout(), clearTimeout(), setInterval() and clearInterval() methods, and show how to use them to set timers and create delayed actions.
JavaScript features a handy couple of methods of the window object: setTimeout() and setInterval(). These let you run a piece of JavaScript code at some point in the future. In this tutorial we'll explain how these two methods work, and give some practical examples.
|
|
|
|
In the last part I showed you how to display alert boxes and how to get information from the user. I also explained how variables work.
document.writeln
This command is very useful as it will output information to a web page. I will start with a basic example of how to use it:
|
|
|
|
| previous< 9 10 11 12 13 14 15 16 17 > Next |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|