BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
JavaScript
JavaScript String Object
JavaScript Object Orientation
JavaScript Objects
JavaScript Number <=> String Conversion
JavaScript Nothingness
JavaScript Math Object Functions
JavaScript Math Object
JavaScript Functions
JavaScript Form
JavaScript Error (try/catch/finally)
JavaScript Date Object Functions
JavaScript Date Object
JavaScript Loops
JavaScript Operators
JavaScript Conditional Statements
JavaScript Boolean Object
JavaScript Assertiveness
JavaScript Array Object Functions
JavaScript Arrays
JavaScript Variables
 
LAMP >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :5065

 

JavaScript String Object Functions

Introduction

The String object contains 28 functions, which can be used to manipulate the string. In this section you will see these 28 functions in some small examples. Please take a look at the string object, if you need more information about that. All functions are used with the String object. The following examples demonstrate this.

JavaScript anchor Function
JavaScript big Function
JavaScript blink Function
JavaScript bold Function
JavaScript charAt Function
JavaScript charCodeAt Function
JavaScript concat Function
JavaScript fixed Function
JavaScript fontcolor Function
JavaScript fontsize Function
JavaScript fromCharCode Function
JavaScript indexOf Function
JavaScript italics Function
JavaScript lastIndexOf Function
JavaScript link Function
JavaScript small Function
JavaScript strike Function
JavaScript sub Function
JavaScript sup Function
JavaScript split Function
JavaScript slice Function
JavaScript substring Function
JavaScript substr Function
JavaScript match Function
JavaScript replace Function
JavaScript search Function
JavaScript toLowerCase Function
JavaScript toUpperCase Function

JavaScript anchor Function

The anchor function can be used to wrap the string into a link anchor.

<html>

<head>

<script type="text/javascript">

            var strLinkAnchor = new String("top")

            strLinkAnchor = strLinkAnchor.anchor("top")

            document.write(strLinkAnchor)

</script>

</head>

<body></body>

</html>

Output

top

JavaScript big Function

The big function can be used to make to string to appear in <big> tag.

<html>

<head>

<script type="text/javascript">

            var str = new String("top")

            str = str.big("top")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

top

JavaScript blink Function

The blink method can be used to make the string blink. This function only works in netscape. IE doesn’t support it yet.

<html>

<head>

<script type="text/javascript">

            var str = new String("top")

            str = str.blink("top")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

top

JavaScript bold Function

This function is used to wrap the string into the <bold> tag.

<html>

<head>

<script type="text/javascript">

            var str = new String("top")

            str = str.bold("top")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

top

JavaScript fixed Function

This function is used to wrap the string in the <TT> tag.

<html>

<head>

<script type="text/javascript">

            var str = new String("top")

            str = str.fixed("top")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

top

JavaScript italics Function

This function wraps the string in the <i> tag.

<html>

<head>

<script type="text/javascript">

            var str = new String("top")

            str = str.italics("top")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

top

JavaScript small Function

This function is used to wrap the string into the <small> tag.

<html>

<head>

<script type="text/javascript">

            var str = new String("top")

            str = str.small("top")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

top

JavaScript strike Function

This function is used to wrap the string into the <strike> tag.

<html>

<head>

<script type="text/javascript">

            var str = new String("top")

            str = str.strike("top")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

top

JavaScript sub Function

This function is used to wrap the string in the <sub> tag.

<html>

<head>

<script type="text/javascript">

            var str = new String("top")

            str = str.sub("top")

            document.write(str)

</script>

</head>

<body>Normal Text</body>

</html>

Output

top Normal Text

JavaScript sup Function

This function can be used to wrap the string in the <sup> tag.

<html>

<head>

<script type="text/javascript">

            var str = new String("top")

            str = str.sup("top")

            document.write(str)

</script>

</head>

<body>Normal Text</body>

</html>

Output

top Normal Text

JavaScript charAt Function

This function can be used to retrieve the character at the given index.

<html>

<head>

<script type="text/javascript">

            var str = new String("top")

            str = str.charAt(1)

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

o

JavaScript charCodeAt Function

This function can be used to convert the char at the given index to the ASCII value.

<html>

<head>

<script type="text/javascript">

            var str = new String("ABC")

            str = str.charCodeAt(0)

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

65

JavaScript indexOf Function

This function can be used to return the index of the given character.

<html>

<head>

<script type="text/javascript">

            var str = new String("ABC")

            str = str.indexOf("B")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

1

JavaScript lastIndexOf Function

This function can be used to return the last index of a given character.

<html>

<head>

<script type="text/javascript">

            var str = new String("ABCB")

            str = str.lastIndexOf("B")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

3

JavaScript link Function

The link method can be used to create a link with the specified string as the URL.

<html>

<head>

<script type="text/javascript">

            var str = new String("TopXML")

            str = str.link("http://www.topxml.com")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

TopXML

JavaScript concat Function

The concat function can be used to concat a string to another one.

<html>

<head>

<script type="text/javascript">

            var str = new String("Hello")

            str = str.concat(" World")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

Hello World

JavaScript fromCharCode Function

This function can be used to return a string from a number of Unicode character values. This function cannot be called with a string object, instead use String.formCharCode.

<html>

<head>

<script type="text/javascript">

            str = String.fromCharCode(65, 66, 67)

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

ABC

JavaScript split Function

The split function can be used to split a string into an array of sub strings.

<html>

<head>

<script type="text/javascript">

            str = new String("0,1,2,3")

            str = str.split(",")

            document.write(str[0]+"<br/>")

            document.write(str[1]+"<br/>")

            document.write(str[2]+"<br/>")

            document.write(str[3]+"<br/>")

</script>

</head>

<body></body>

</html>

Output

0

1

2

3

JavaScript slice Function

The slice function can be used to slice a specific section and return a new string.

<html>

<head>

<script type="text/javascript">

            str = new String("Hello World")

            str = str.slice(5,11)

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

World

JavaScript substring Function

The function substring can be used to get a specific section from a string. It basically works the same as the slice function.

<html>

<head>

<script type="text/javascript">

            str = new String("Hello World")

            str = str.substring(5,11)

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

World

JavaScript substr Function

The function substr can be used to get a specific section from a string. It works the same as slice and substring.

<html>

<head>

<script type="text/javascript">

            str = new String("Hello World")

            str = str.substr(5,11)

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

World

JavaScript match Function

The match function can be used to match a regular expression against a string. It returns an array of the matches.

<html>

<head>

<script type="text/javascript">

            str = new String("Hello World")

            str = str.match("H")

            for(i=0;i<str.length;i++)

            {

                        document.write(str[i]+"<br/>")

            }

</script>

</head>

<body></body>

</html>

Output

H

JavaScript replace Function

The function replace can be used to replace a string with another string. A regular expression can be used to find the string.

<html>

<head>

<script type="text/javascript">

            var str = new String("Hello World")

            document.write(str+"<br/>")

            var regEx = new RegExp ('World', 'gi') ;

            str = str.replace(regEx, 'User')

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

Hello World

Hello User

JavaScript search Function

This function can be used to in conjunction with a regular expression to search for a specific format.

<html>

<head>

<script type="text/javascript">

            strWrongEmail = new String("sonu_sonu.com")

            emailRegEx = /^[^@]+@[^@]+.[a-z]{2,}$/i

            if(strWrongEmail.search(emailRegEx) == -1){

                        document.write("Email is not valid")

            }

            else

                        document.write("Email is valid")

</script>

</head>

<body></body>

</html>

Output

Email is not valid

JavaScript toLowerCase Function

This function can be used to convert the string to lower case.

<html>

<head>

<script type="text/javascript">

            str = new String("HELLO WORLD")

            str = str.toLowerCase()

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

hello world

JavaScript toUpperCase Function

This function is used to convert the string to upper case.

<html>

<head>

<script type="text/javascript">

            str = new String("hello world")

            str = str.toUpperCase()

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

HELLO WORLD

JavaScript fontcolor Function

The fontcolor function can be used to wrap the string in the <font> tag, which changes the color of the string.

<html>

<head>

<script type="text/javascript">

            str = new String("hello world")

            str = str.fontcolor("red")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

hello world

JavaScript fontsize Function

The fontsize function can be used to change the font size of the string.

<html>

<head>

<script type="text/javascript">

            str = new String("hello world")

            str = str.fontsize("12")

            document.write(str)

</script>

</head>

<body></body>

</html>

Output

hello world


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

An immediate job opportunity as a B
Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C

View all Jobs (Add yours)
View all CV (Add yours)



answering service
conference calling
swimming pool builder
spfxmasks
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP