www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons JavaScript String Object Functions and Properties Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Lesson 45
Lesson 46
Lesson 47
Lesson 48
Lesson 49
In one of the previous lessons we have learned about basics of JavaScript Strings. In this lesson we will explore JavaScript String property and functions.

String manipulation is an important part of JavaScript programming language. We use the built-in String object to manipulate string in JavaScript. The string object has almost 28 functions for working with text.

As you already know that the strings in JavaScript are enclosed within double quotes. They can also be enclosed within single quotes. BUT remember that if you are starting a string with a single quote, you must end it with a single quote. Same is the case with the double quotes. Mixing quotes may produce undesireable results.

Using the lengt property of the String object:
Just like arrays the String object in JavaScript also has the length property that works the same way. We can find out the length of a given string by using the .length property of the String object as under:

<script type="text/JavaScript">
var str = "String";
alert(str.length); // would outpu 6
</script>

JavaScript String Object Functions / Methods are summarized in the following table:
Function Description
anchor(name) Returns the string with the tag <A name="name"> surrounding it.
big() Returns the string with the tag <BIG> surrounding it.
blink() Returns the string with the tag <BLINK> surrounding it.
bold() Returns the string with the tag <B> surrounding it.
fixed() Returns the string with the tag <TT> surrounding it.
fontcolor(color) Returns the string with the tag <FONT color="color"> surrounding it. .
fontsize(size) Returns the string with the tag <FONT size="size"> surrounding it.
italics() Returns the string with the tag <I> surrounding it.
link(url) Returns the string with the tag <A href="url"> surrounding it.
small() Returns the string with the tag <SMALL> surrounding it.
strike() Returns the string with the tag <STRIKE> surrounding it.
sub() Returns the string with the tag <SUB> surrounding it.
sup() Returns the string with the tag <SUP> surrounding it.
charAt(num) Returns the character at the "num" position within the string.
charCodeAt(num) Returns the Unicode value of the character at position "num" within the string.

concat(str1, str2, ...) Combines one or more strings (str1, str2, ...) into the existing one and returns the combined string. Original string is not modified.

fromCharCode(c1, c2, ...) Returns a string created by using the specified sequence of Unicode values (c1, c2, ...). This method is not associated with a string instance, but with the String class. We call it using the syntax String.fromCharCode(......), and not by varString.fromCharCode(......), where varString is a string variable.

indexOf(substr [start]) Searches and (if found) returns the index number of the searched character or substring within the string. If not found -1 is returned. "Start" is an optional argument specifying the position within string to begin the search. Default is 0.

lastIndexOf(substr [start]) Searches and (if found) returns the index number of the searched character or substring within the string. Searches the string from end to beginning. If not found -1 is returned. "Start" is an optional argument specifying the position within string to begin the search. Default is string.length-1.

match(regexp) Executes a search for a match within a string based on a regular expression. It returns an array of information or null if no match is found.

replace( regexp replacetext) Searches and replaces the regular expression portion (match) with the replaced text instead.

search(regexp) Tests for a match in a string. It returns the index of the match or -1 if not found.

slice(start [end]) Returns a substring of the string based on the "start" and "end" index arguments NOT including the "end" index itself. "End" is optional and if none is specified the slice includes all characters from "start" to end of string.

split(delimiter [limit]) Splits a string into many according to the specified delimiter and returns an array containing each element. The optional "limit" is an integer that lets you specify the maximum number of elements to return.

substr(start [length]) Returns the characters in a string beginning at "start" and through the specified number of characters "length". "Length" is optional and if omitted up to the end of the string is assumed.

substring(from [to]) Returns the characters in a string between "from" and "to" indexes NOT including "to" inself. "To" is optional and if omitted up to the end of the string is assumed.

toLowerCase() Returns the string with all of its characters converted to lowercase.

toUpperCase() Returns the string with all of its characters converted to uppercase.


Next >>> Lesson No. 34: JavaScript Date Object





Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.