Actionscript Course

Strings can be any piece of textual data : words, characters, numbers or paragraphs; added between quotes (single or double).
Everything in ActionScript 3.0 is an object, including strings. When you type a string like "Have a good life" you're creating an instance of the String class.


You can create a variable that contains Strings data type by using any of the following syntaxes:
                var var_name:String = "Some text";
                var var_name:String = new String("Some text");
                var var_name:String = String("Some text");
Quotes tell the program that the text contained within them should be interpreted as a String.
You can use single or double quotes, doesn't matter, but how you use them does.
If your text contains double quotes, add it between single quotes.
And vice versa, if your text contains single quotes, add it between double quotes.
  - For example:
var str1:String = "Free 'Courses' coursesweb.net";
var str2:String = 'Free "Courses" marplo.net';

Using escaped characters

If you want to add the same quote mark within a string, the quotes contained in text must be escaped (preceded by a backslash (\)). This tells the compiler to interpret the escaped quote as part of the text, not as the end of the string.
  - For example:
var str1:String = "Free \"Courses\" coursesweb.net";
var str2:String = 'Free \'Courses\' marplo.net';

Escaped caracters are specific characters preceded by backslash (\). They tell the program to replace them with the real characters.
There are several escape characters:
To join multiple strings together, use the addition (+) operator:
  var str1:String = ' Lessons ';
  var str2:String = 'Tutorials';
  var str3:String = 'Courses'+ str1+ str2;
  trace(str3);             // Courses Lessons Tutorials

Properties and Methods of the String object

ActionScript has special properties and methods for working with strings, which can make various handling operations, searching terms, conversions.

The String object has only one property, length. This property returns an integer specifying the number of characters in string.
  - Example:
var str:String = "Any text";
trace(str.length);             // 8

Methods

charAt(index) - returns the character in the position specified by the "index" parameter.
var str:String = "Some text";
trace(str.charAt(3));             // e

charCodeAt(index) - returns the numeric Unicode character code of the character at the specified "index".
var str:String = "Un sir";
trace(str.charCodeAt(3));             // 115

concat('str1', 'str2', ...) - appends the arguments to the end of the string (converting them to strings if necessary), and returns the resulting string.
var str:String = "Test ";
trace(str.concat('str1', ' str2'));             // Test str1 str2

fromCharCode(code1, code2) - returns a string comprising the characters represented by the Unicode character codes in the parameters.
trace(String.fromCharCode(115, 118));             // sv

indexOf('substring', startIndex) - searches the string and returns the position of the first occurrence of "substring" found at or after "startIndex" within the calling string.
var str:String = "Tutorials";
trace(str.indexOf('tor'));             // 2 

lastIndexOf('substring', startIndex) - searches the string from right to left and returns the index of the last occurrence of "substring" found before startIndex.
var str:String = "Tutorials, in online courses";
trace(str.lastIndexOf('in'));             // 17

match(pattern) - matches the specifed "pattern" against the string.
var str:String = "Tutorials, tutor, courses";
var exp:RegExp = /tu[a-z]+/gi;
trace(str.match(exp));             // Tutorials,tutor 

replace(pattern, 'repl') - matches the specifed pattern against the string and returns a new string in which the match of "pattern" is replaced with the content specified by "repl".
var str:String = "Tutorials, tutor, courses";
var exp:RegExp = /tu[a-z]+/gi;
trace(str.replace(exp, 'Lessons'));             // Lessons, Lessons, cursuri 

search(pattern) - searches for the specifed "pattern" and returns the index of the first matching substring.
var str:String = "Tutorials, tutor, courses";
var exp:RegExp = /r[is]/i;
trace(str.search(exp));             // 4 

slice(startIndex, endIndex) - returns a string that includes the "startIndex" character and all characters up to, but not including, the "endIndex" character.
var str:String = "ActionScript free online";
trace(str.slice(13, 17));             // free

split('sep') - splits a string into an array of substrings by dividing it wherever the "sep" parameter occurs.
var str:String = "Free-online-ActionScript";
trace(str.split('-'));             // Free,online,ActionScript

substr(startIndex, len) - returns a substring consisting of the characters that start at the specified "startIndex" and with a length specified by "len".
var str:String = "https://marplo.net";
trace(str.substr(11, 6));             // marplo

toLowerCase() - returns a copy of this string, with all uppercase characters converted to lowercase.
var str:String = "Tutorials, Courses ONLINE";
trace(str.toLowerCase());             // tutorials, courses online

toUpperCase() - returns a copy of this string, with all uppercase characters converted to uppercase.
var str:String = "Tutorials, Courses ONLINE";
trace(str.toLowerCase());             // TUTORIALS, COURSES ONLINE

toString() - converts the object into string.
var nr:int = 7;
var str:String = '8';
trace(nr.toString()+ str);             // 78     (or String(nr)+ str ) 

Number('str') - converts the 'str' string into number.
var nr:int = 7;
var str:String = '8';
trace(nr+ Number(str));             // 15

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag is used to add lists into <ul> and <ol> elements?
<dt> <dd> <li>
<ul>
 <li>http://coursesweb.net/html/</li>
 <li>http://coursesweb.net/css/</li>
</ul>
Which value of the "display" property creates a block box for the content and ads a bullet marker?
block list-item inline-block
.some_class {
  display: list-item;
}
Which instruction converts a JavaScript object into a JSON string.
JSON.parse() JSON.stringify eval()
var obj = {
 "courses": ["php", "javascript", "ajax"]
};
var jsonstr = JSON.stringify(obj);
alert(jsonstr);    // {"courses":["php","javascript","ajax"]}
Indicate the PHP class used to work with HTML and XML content in PHP.
stdClass PDO DOMDocument
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>';
$dochtml = new DOMDocument();
$dochtml->loadHTML($strhtml);
$elm = $dochtml->getElementById("dv1");
echo $elm->nodeValue;    // CoursesWeb.net
String Object

Last accessed pages

  1. Shape Tween - Flash Animation (6149)
  2. The Mastery of Love (7440)
  3. Get Mime Type of file or string content in PHP (6230)
  4. Countdown Timer with starting time added into a form (11533)
  5. Disable button and Enable it after specified time (17533)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (477)
  2. CSS cursor property - Custom Cursors (81)
  3. The Mastery of Love (72)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (64)
  5. CSS3 2D transforms (46)