// --------------------------------------------------------// Theorie: String Methoden// --------------------------------------------------------// Für String Variablen definiert die JavaScript SprachSpezifikation// eine Reihe von Feldern und Methoden// String Attribute// -> length// String Methoden:// -> charAt// -> charCodeAt// -> endsWith// -> includes// -> indexOf// -> lastIndexOf// -> repeat// -> replace// -> slice// -> split// -> startsWith// -> substring// -> toUpperCase// -> toLowerCase// -> trim// Anwenden einer Stringfunktion// var a = "hello World";// Syntax: <name>.<functions-name>();// a.toUpperCase();// Hinweis: Die Stringmethode verändert nie den String selbst sondern gibt// eine veränderte Version des Strings zurück.// -- ---------------------------------------------------------------------------- --// -- 1.Beispiel - Stringmethoden// -- ---------------------------------------------------------------------------- --// Wieviel Buchstaben hat der in der Variable gespeicherte Name?console.log("-- ------------------------------------------------- --");console.log("-- 1.Exercise: length");console.log("-- ------------------------------------------------- --");var firstName = "Otto";// -- ---------------------------------------------------------------------------- --// -- 2.Beispiel - Stringmethoden: toUpperCase/toLowerCase// -- ---------------------------------------------------------------------------- --// The toLowerCase() method returns the string converted to lowercase.// Syntax: toLowerCase()// The toUpperCase() method returns the string converted to uppercase.// Syntax: toUpperCase()console.log("-- ------------------------------------------------- --");console.log("-- 2.Exercise: toUpperCase/toLowerCase");console.log("-- ------------------------------------------------- --");// Alle Buchstaben im folgenden Namen sollen zuerst in Großbuchstaben umgewandelt// dann in Kleinbuchstaben umgewandelt werden. Geben Sie den Namen nach jeder// Änderung auslet cityName = "Vienna";// -- ---------------------------------------------------------------------------- --// -- 3.Beispiel - Stringmethoden: replace/replaceAll// -- ---------------------------------------------------------------------------- --// The replace() method returns a new string with the specified// string replaced. Works only with the first occurance of the// element// Syntax: replace(element, replacement)//// @element [required]: token that is to be replaced// @replacement [required]: the replacementtoken// The replaceAll() method returns a new string with all matches of a// pattern replaced by a replacement.// Syntax: replaceAll(element, replacement)//// @element [required]: token that is to be replaced// @replacement [required]: the replacementtokenconsole.log("-- ------------------------------------------------- --");console.log("-- 3.Exercise: replace/replaceAll");console.log("-- ------------------------------------------------- --");// Ersetzen Sie alle Umlaute im folgenden Ausdruck mit ue, ae, oe.// Geben Sie die Werte anschließend aus.var email = "kaiserlicheösterreichischeÄnderungs@alora.com";// Ersetzen sie alle Vorkommen des Strings php mit JavaScriptvar sentence = "php ist eine tolle Programmiersprache. Lernen Sie php!";// -- ---------------------------------------------------------------------------- --// -- 4.Beispiel - Stringmethoden: charAt// -- ---------------------------------------------------------------------------- --// The charAt() method returns the character at the specified index in a string.// Syntax: charAt(index)//// @index [optional]: An integer between 0 and str.length -1. If index// is not provided, the default value 0 is usedconsole.log("-- ------------------------------------------------- --");console.log("-- 4.Exercise: charAt");console.log("-- ------------------------------------------------- --");// Mit welchem Buchstaben beginnt bzw. endet das gewünschte Wort? Geben// Sie beide Buchstaben aus. Wandeln Sie die Buchstaben in Großbuchstaben// um.var game = "D&D: Journeys in the dark";// Lösung:// -- ---------------------------------------------------------------------------- --// -- 5.Beispiel - Stringmethoden: indexOf/lastIndexOf// -- ---------------------------------------------------------------------------- --// The string indexOf() method returns the index of the first occurence of the// substring in a string.// Syntax: indexOf(searchValue, fromIndex)//// @searchValue [optional]: The value to search for in the string.// If no string is provided explicitly, "undefined"// will be searched.// @fromIndex [optional]:The index to start the search at. By default it is 0.// If fromIndex < 0, the search starts at index 0.// The lastIndexOf() method returns the last index of occurence of a given// substring in the string.// Syntax: lastIndexOf(substr, fromIndex)//// @substr - The value to search for in the given string.// @fromIndex (optional) - The index to start searching the string backwards.// By default it is +Infinity.console.log("-- ------------------------------------------------- --");console.log("-- 5.Exercise: indexOf");console.log("-- ------------------------------------------------- --");var email = "h.macho@htlkrems.at";// Geben Sie den Index des @ Zeichens aus.// Geben Sie den Index des zweiten . Zeichens aus:// -- ---------------------------------------------------------------------------- --// -- 6.Beispiel - Stringmethoden: substring// -- ---------------------------------------------------------------------------- --// The substring() method returns a specified part of the string between start and// end indexes.// Syntax: substring(indexStart, indexEnd)//// @indexStart - The index of the first character to start including// in the returned substring.// @indexEnd (optional) - The index before which to stop extraction.// (Exclusive) If omitted, it extracts till the end of the string.console.log("-- ------------------------------------------------- --");console.log("-- 6.Exercise: substring");console.log("-- ------------------------------------------------- --");// Geben Sie für eine email den identifier und die domain aus.// Aufbau email: <identifier>@<domain>var hemail = "h.macho@htlkrems.at";// -- ---------------------------------------------------------------------------- --// -- 7.Beispiel - Stringmethoden: split// -- ---------------------------------------------------------------------------- --// The split() method divides a string into a list of substrings and returns// them as an array.// Syntax: split(separator, limit)//// @separator (optional) - The string describing where each split should occur.// @limit (optional) - A non-negative integer limiting the number of pieces// to split the given string into.console.log("-- ------------------------------------------------- --");console.log("-- 7.Exercise: split");console.log("-- ------------------------------------------------- --");// Für den folgenden Satz soll für jedes Wort die Anzahl der Buchstaben in// einem Array gespeichert werden.var movie = "Dungeons & Dragons : No Honor among thieves";