Java Script provides the built-in String object that provides you with many methods for searching and manipulating strings. In this article I will provide you with examples that show you how to use the most important methods of the string object.
Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022

Java Script Strings

In programming, the word "string" refers to an array of characters like a sentence or a paragraph. JavaScript provides a built-in String object which provides you with many methods for searching and manipulating strings. You can use the String object constructor to create a String object as shown below.

<script type="text/javascript">
var myString = new String("This is my string.");
alert(myString);
</script>

Note that the string must be contained within quotation marks. In fact, when you assign a string of characters within quotation marks to a variable in JavaScript, as shown below, it is automatically converted to a string.

<script type="text/javascript">
var myString = "This is my string.";
alert(myString);
</script>

In fact, the keyword var is not strictly necessary, as the "=" character will automatically assume that you are creating and assigning a variable, although I consider it bad programming practice to leave it out.

Concatenating Strings

To concatenate means to connect together. If you need to concatenate two or more strings, you can use the String object's concat method, as shown below.

<script type="text/javascript">
var firstString = "Now is the time for all good men ";
var secondString = "to come to the aid of their country.";

var myString = firstString.concat(secondString);
alert(myString);
</script>

In fact you can use the concat method to connect any number of strings together by separating the strings names with commas, using the syntax shown below.

string.concat(string1, string2, ... ,stringN)

In fact, using the concat method is not strictly necessary, as you can use the "+" operator to concatenate strings as shown below.

<script type="text/javascript">
var strFirst = "John";
var strLast = "Kennedy";
var strFull = strFirst + "F." + strLast;
alert(strFull);
</script>

RSS Feed RSS Feed



Follow Stephen Bucaro Follow @Stephen Bucaro


Web Design Sections

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2016 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268