JavaScript String
Object
It is a built-in or standard object in javascript.
JavaScript support different built in object.
1. String
2. RegExp
3. Boolean
4. Number
5. Array
6. Math
7. Date
The String Object
A string is a sequence of
characters. All strings are represented as an instances of the string object.
It is used to perform operation on stored text. String object is wrapper class
and a member of the global objects.
Properties of string object
Property
|
Description
|
constructor
|
Returns the function which creates the prototype of a string object
|
Length
|
Returns the length of a string
|
prototype
|
Adds properties and methods to an object
|
Methods of the String Object
Method
|
Description
|
charAt()
|
Returns the character in the specified index
|
charCodeAt()
|
Returns the Unicode equivalence of the character in the specified
index
|
concat()
|
Joins two strings and returns the joint string
|
fromCharCode()
|
Coverts the Unicode to character
|
indexof()
|
Returns the position of the first occurrence of the specified
character in a string
|
lastindexof()
|
Returns the position of the last occurrence of the specified
character in a string
|
match()
|
Looks for the match between a regular expression and a string and
returns the matches
|
quote()
|
Writes quotes in javaScript
|
replace()
|
Searches for the match between a regular expression and a string, and
replace the match substring with a new substring.
|
search()
|
Searches for the match between a regular expression and a string and
returns the position of the match
|
slice()
|
Returns a part of a string as new string
|
substr()
|
Splits a string into substrings
|
substring()
|
Returns characters in a string between two specified indices
|
toLowerCase()
|
Converts a string into lowercase
|
toUpperCase()
|
Converts a string into uppercase
|
toSource()
|
Returns an object literal representing the specified object
|
toString()
|
Returns a string representing the specified object
|
valueOf()
|
Returns the primitive value of a string object.
|
Wrapper methods that returns a string object
Method
|
Description
|
anchor()
|
Creates an anchor
|
big()
|
Shows string with a big font
|
blink()
|
Makes the string to blink
|
bold()
|
Makes the string bold
|
fixed()
|
Displays the string using fixed pitch font, such as courier new or
book antique
|
fontcolor()
|
Shows string with specified color
|
fontsize()
|
Shows string with specified size
|
italics()
|
Shows the string in italics
|
link()
|
Shows the string as a hyperlink
|
small()
|
Shows a string with small font
|
strike()
|
Shows the string with the struck out text
|
sub()
|
Shows the string as a subscript text
|
sup()
|
Shows the string as a superscript text
|
Example
<!DOCTYPE html>
<html>
<head>
<title>JavaScript String Objects</title>
</head>
<body>
<h1>JavaScript String Objects</h1>
<script>
var var_string = 'Once upon a time';
document.write('string: ' + var_string + '<br/>');
document.write('lenght: ' + var_string.length + '<br/>');
document.write('uppercase: ' + var_string.toUpperCase() + '<br/>');
document.write('lowercase: ' + var_string.toLowerCase() + '<br/>');
document.write('strike text: ' + var_string.strike() + '<br/>');
document.write('bold text: ' + var_string.bold() + '<br/>');
document.write('big text: ' + var_string.big() + '<br/>');
document.write('small text: ' + var_string.small() + '<br/>');
document.write('blinking text: ' + var_string.blink() + '<br/>');
document.write('substring after 5 character: ' + var_string.substring(5) + '<br/>');
document.write('character at 5 position ' + var_string.charAt(5) + '<br/>');
document.write('Index of text: ' + var_string.indexOf('upon') + '<br/>');
document.write('splitted text: ' + var_string.split('upon') + '<br/>');
</script>
</body>
</html>
0 comments:
Post a Comment