From 95aca4b4d8fa62815d4bd412fff1a364f842814a Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 29 Apr 2021 16:16:42 -0700 Subject: remove retired locales (#699) --- .../global_objects/string/charat/index.html | 247 ------------- .../global_objects/string/includes/index.html | 188 ---------- .../reference/global_objects/string/index.html | 410 --------------------- .../global_objects/string/indexof/index.html | 151 -------- .../global_objects/string/length/index.html | 90 ----- .../reference/global_objects/string/raw/index.html | 108 ------ 6 files changed, 1194 deletions(-) delete mode 100644 files/it/web/javascript/reference/global_objects/string/charat/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/string/includes/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/string/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/string/indexof/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/string/length/index.html delete mode 100644 files/it/web/javascript/reference/global_objects/string/raw/index.html (limited to 'files/it/web/javascript/reference/global_objects/string') diff --git a/files/it/web/javascript/reference/global_objects/string/charat/index.html b/files/it/web/javascript/reference/global_objects/string/charat/index.html deleted file mode 100644 index 312cfa9713..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/charat/index.html +++ /dev/null @@ -1,247 +0,0 @@ ---- -title: String.prototype.charAt() -slug: Web/JavaScript/Reference/Global_Objects/String/charAt -translation_of: Web/JavaScript/Reference/Global_Objects/String/charAt ---- -
{{JSRef}}
- -

Il metodo {{jsxref("String")}} dell'oggetto charAt() restituisce una nuova stringa che consiste nella singola unità di codice UTF-16 situata nell'offset specificato nella stringa.

- -
{{EmbedInteractiveExample("pages/js/string-charat.html")}}
- - - -

Sintassi

- -
carattere = str.charAt(indice)
- -

Parametri

- -
-
index
-
Un numero intero compreso tra 0 e 1-meno della lunghezza della stringa. Se non viene fornito alcun indice, il valore predefinito è 0, quindi viene restituito il primo carattere nella stringa.
-
- -

Valore restituito

- -

Una stringa che rappresenta il carattere (esattamente un'unità di codice UTF-16) nell'indice specificato; stringa vuota se index non è compreso nell'intervallo

- -

Descrizione

- -

I caratteri in una stringa sono indicizzati da sinistra a destra. L'indice del primo carattere è 0 e l'indice dell'ultimo carattere in una stringa chiamata stringName è stringName.length - 1. Se l'indice che fornisci è fuori da questo intervallo, JavaScript restituisce una stringa vuota.

- -

Se non viene fornito alcun indice per charAt(), il valore predefinito è 0.

- -

Esempi

- -

Visualizzazione di caratteri in posizioni diverse in una stringa

- -

Nell'esempio seguente vengono visualizzati caratteri in posizioni diverse nella stringa "Brave new world":

- -
var anyString = 'Brave new world';
-console.log("Il carattere nell'indice 0 è '" + anyString.charAt()   + "'");
-// Non è stato fornito alcun indice, usato 0 come predefinito
-
-console.log("The character at index 0   is '" + anyString.charAt(0)   + "'");
-console.log("The character at index 1   is '" + anyString.charAt(1)   + "'");
-console.log("The character at index 2   is '" + anyString.charAt(2)   + "'");
-console.log("The character at index 3   is '" + anyString.charAt(3)   + "'");
-console.log("The character at index 4   is '" + anyString.charAt(4)   + "'");
-console.log("The character at index 999 is '" + anyString.charAt(999) + "'");
-
- -

Queste righe mostrano quanto segue:

- -
//Il carattere nell'indice 0   is 'B'
-
-//Il carattere nell'indice 0   is 'B'
-//Il carattere nell'indice 1   is 'r'
-//Il carattere nell'indice 2   is 'a'
-//Il carattere nell'indice 3   is 'v'
-//Il carattere nell'indice 4   is 'e'
-//Il carattere nell'indice 999 is ''
-
- -

Recupero di caratteri interi

- -

Quanto segue fornisce un mezzo per garantire che l'attraversamento di un loop string fornisca sempre un intero carattere, anche se la stringa contiene caratteri che non si trovano nel piano multi-lingue di base.

- -
var str = 'A \uD87E\uDC04 Z'; // Potremmo anche usare direttamente un carattere non-BMP
-for (var i = 0, chr; i < str.length; i++) {
-  if ((chr = getWholeChar(str, i)) === false) {
-    continue;
-  }
-  // Adatta questa linea all'inizio di ogni ciclo, passando l'intera stringa e
-  // l'iterazione corrente e il ritorno di una variabile per rappresentare il
-  // personaggio individuale
-
-  console.log(chr);
-}
-
-function getWholeChar(str, i) {
-  var code = str.charCodeAt(i);
-
-  if (Number.isNaN(code)) {
-    return ''; // Posizione non trovata
-  }
-  if (code < 0xD800 || code > 0xDFFF) {
-    return str.charAt(i);
-  }
-
-  // Alto surrogato (potrebbe cambiare l'ultimo esadecimale a 0xDB7F per trattare un alto privato
-   // si surroga come singoli caratteri)
-  if (0xD800 <= code && code <= 0xDBFF) {
-    if (str.length <= (i + 1)) {
-      throw 'Alto surrogato senza seguire un surrogato basso';
-    }
-    var next = str.charCodeAt(i + 1);
-      if (0xDC00 > next || next > 0xDFFF) {
-        throw 'Alto surrogato senza seguire un surrogato basso';
-      }
-      return str.charAt(i) + str.charAt(i + 1);
-  }
-  // Low surrogate (0xDC00 <= code && code <= 0xDFFF)
-  if (i === 0) {
-    throw 'Basso surrogato senza precedente surrogato elevato';
-  }
-  var prev = str.charCodeAt(i - 1);
-
-  // (could change last hex to 0xDB7F to treat high private
-  // surrogates as single characters)
-  if (0xD800 > prev || prev > 0xDBFF) {
-    throw 'Basso surrogato senza precedente surrogato elevato';
-  }
-  // Ora possiamo passare sopra surrogati bassi come secondo componente
-   // in una coppia che abbiamo già elaborato
-  return false;
-}
-
- -

In un ambiente ECMAScript 2016 che consente l'assegnazione destrutturata, la seguente è un'alternativa più succinta e un po 'più flessibile in quanto incrementa automaticamente una variabile incrementale (se il carattere lo richiede in quanto coppia surrogata).

- -
var str = 'A\uD87E\uDC04Z'; // Potremmo anche usare direttamente un carattere non-BMP
-for (var i = 0, chr; i < str.length; i++) {
-  [chr, i] = getWholeCharAndI(str, i);
-  // Adatta questa linea all'inizio di ogni ciclo, passando l'intera stringa e
-  // l'iterazione corrente e la restituzione di un array con il singolo carattere
-  // e valore "i" (modificato solo se una coppia surrogata)
-
-  console.log(chr);
-}
-function getWholeCharAndI(str, i) {
-  var code = str.charCodeAt(i);
-  if (Number.isNaN(code)) {
-    return ''; // Posizione non trovata
-  }
-  if (code < 0xD800 || code > 0xDFFF) {
-    return [str.charAt(i), i]; // Carattere normale, mantenendo 'i' lo stesso
-  }
-  // Alto surrogato (potrebbe cambiare l'ultimo esadecimale a 0xDB7F per trattare un alto privato
-  // si surroga come singoli caratteri)
-  if (0xD800 <= code && code <= 0xDBFF) {
-    if (str.length <= (i + 1)) {
-      throw "Alto surrogato senza seguire un surrogato basso";
-    }
-    var next = str.charCodeAt(i + 1);
-      if (0xDC00 > next || next > 0xDFFF) {
-        throw "Alto surrogato senza seguire un surrogato basso";
-      }
-      return [str.charAt (i) + str.charAt (i + 1), i + 1];
-  }
-  // Basso surrogato (0xDC00 <= code && code <= 0xDFFF)
-  if (i === 0) {
-    throw "Basso surrogato senza precedente surrogato elevato";
-  }
-  var prev = str.charCodeAt(i - 1);
-  // (potrebbe cambiare l'ultimo esadecimale in 0xDB7F per trattare i surrogati ad alto livello privato
-  // come singoli caratteri)
-  if (0xD800 > prev || prev > 0xDBFF) {
-    throw "Basso surrogato senza precedente surrogato elevato";
-  }
-  // Restituisce invece il carattere successivo (e incrementa)
-  return [str.charAt(i + 1), i + 1];
-}
-
- -

Correggere charAt() per supportare caratteri non-Basic-Multilingual-Plane (BMP)

- -

Mentre l'esempio sopra può essere più frequentemente utile per coloro che desiderano supportare caratteri non BMP (dal momento che non richiede al chiamante di sapere dove potrebbe apparire un personaggio non BMP), nel caso in cui uno lo desideri, nella scelta di un personaggio per indice, per trattare le coppie surrogate all'interno di una stringa come i singoli caratteri che rappresentano, si può usare quanto segue:

- -
function fixedCharAt(str, idx) {
-  var ret = '';
-  str += '';
-  var end = str.length;
-
-  var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
-  while ((surrogatePairs.exec(str)) != null) {
-    var li = surrogatePairs.lastIndex;
-    if (li - 2 < idx) {
-      idx++;
-    } else {
-      break;
-    }
-  }
-
-  if (idx >= end || idx < 0) {
-    return '';
-  }
-
-  ret += str.charAt(idx);
-
- if (/[\uD800-\uDBFF]/.test(ret) && /[\uDC00-\uDFFF]/.test(str.charAt(idx + 1))) {
-    // Vai avanti, poiché uno dei "personaggi" fa parte di una coppia di sostituti
-    ret += str.charAt(idx + 1);
-  }
-  return ret;
-}
-
- -

Specificazioni

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificazioniStatoCommenti
{{SpecName('ES1')}}{{Spec2('ES1')}}definizione iniziale.
{{SpecName('ES5.1', '#sec-15.5.4.4', 'String.prototype.charAt')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.charat', 'String.prototype.charAt')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.charat', 'String.prototype.charAt')}}{{Spec2('ESDraft')}} 
- -

Compatibilità con il browser

- - - -

{{Compat("javascript.builtins.String.charAt")}}

- -

Guarda anche

- - diff --git a/files/it/web/javascript/reference/global_objects/string/includes/index.html b/files/it/web/javascript/reference/global_objects/string/includes/index.html deleted file mode 100644 index 44eac8fc22..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/includes/index.html +++ /dev/null @@ -1,188 +0,0 @@ ---- -title: String.prototype.includes() -slug: Web/JavaScript/Reference/Global_Objects/String/includes -translation_of: Web/JavaScript/Reference/Global_Objects/String/includes ---- -
{{JSRef}}
- -
Il metodo includes() verifica se una stringa ne contiene un'altra desiderata, restituendo truefalse in base dell'esito della ricerca.
- -
 
- -

Sintassi

- -
str.includes(searchString[, position])
- -

Parametri

- -
-
searchString
-
Una stringa da cercare all'interno di una stringa.
-
position
-
Opzionale. La posizione in questa stringa. La posizione in questa stringa in cui iniziare la ricerca di searchString; il valore predefinito è 0.
-
- -

Valore di ritorno

- -

true se la stringa contiene la stringa di ricerca; altrimenti, false.

- -

Descrizione

- -

Questo metodo permette di determinare se la stringa includa o no un'altra stringa.

- -

Sensitività alle maiuscole

- -

Il metodo includes() è sensibile alle maiuscole. Per esempio, la seguente espressione restituisce false:

- -
'Blue Whale'.includes('blue'); // returns false
-
- -

Esempi

- -

Utilizzando includes()

- -
var str = 'To be, or not to be, that is the question.';
-
-console.log(str.includes('To be'));       // true
-console.log(str.includes('question'));    // true
-console.log(str.includes('nonexistent')); // false
-console.log(str.includes('To be', 1));    // false
-console.log(str.includes('TO BE'));       // false
-
- -

Polyfill

- -

Questo metodo è stato aggiunto alla specifica ECMAScript 2015 e potrebbe essere non disponibile ancora in tutte le implementazioni di JavaScript.

- -
if (!String.prototype.includes) {
-  String.prototype.includes = function(search, start) {
-    'use strict';
-    if (typeof start !== 'number') {
-      start = 0;
-    }
-
-    if (start + search.length > this.length) {
-      return false;
-    } else {
-      return this.indexOf(search, start) !== -1;
-    }
-  };
-}
-
-/*
-https://github.com/FabioVergani/js-Polyfill_StringIncludes/blob/master/StringIncludes.js
-
-(function(s){'use strict';
- var o=s.prototype,p='includes';
- o[p]||(o[p]=function(a,b){//search,start
-  var e=this,i=isNaN(b)?0:b,t=a,l=t.length;
-  return (l<1||((i+l)>e.length))?false:-1!==e.indexOf(t,i);
- });
-})(String);
-
-*/
- -

 

- -

 

- -

 

- -

 

- -

Specificazioni

- - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES6', '#sec-string.prototype.includes', 'String.prototype.includes')}}{{Spec2('ES6')}}Definizioni inizili.
{{SpecName('ESDraft', '#sec-string.prototype.includes', 'String.prototype.includes')}}{{Spec2('ESDraft')}} 
- -

Compatibilità Browser 

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerEdgeOperaSafari
Basic support{{CompatChrome("41")}}{{CompatGeckoDesktop("40")}}{{CompatNo}}14393+{{CompatNo}}{{CompatSafari("9")}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile("40")}}{{CompatNo}}{{CompatNo}}{{CompatNo}}
-
- -

String.prototype.contains

- -

In Firefox 18 - 39, il nome di questo metodo era contains(). E' stato rinominato inincludes() in {{bug(1102219)}} a causa del seguente motivo:

- -

E' stato riportato che alcuni websites che utilizzano MooTools 1.2 non funzionavano su Firefox 17. Tale versione di MooTools controlla se String.prototype.contains() esiste e, se non esiste,  MooTools aggiunge una propria funzione. Con l'introduzione di questa funzione in Firefox 17, il comportamento di tale controllo è cambiato in un modo che il codice basato su String.prototype.contains()  non funzioni. Come risultato, l'implementazione  è stata disabilitata in Firefox 17 e String.prototype.contains() era disponibile nella versione successiva, in Firefox 18, quando outreach to MooTools stava conducendo al rilascio di MooTools version 1.2.6.

- -

MooTools 1.3 forza la propria versione di  String.prototype.contains(), così i siti web che si affidano ad essa non vanno in break. Comunque si noti che la signature di  MooTools 1.3 e quella di ECMAScript 2015 per questo metodo differiscono (sul secondo argomento). Più avanti , MooTools 1.5+ ha cambiato la  signature per incontrare lo standard ES2015.

- -

In Firefox 48, String.prototype.contains() è stato rimosso. Usare String.prototype.includes() solamente.

- -

Vedere anche

- - diff --git a/files/it/web/javascript/reference/global_objects/string/index.html b/files/it/web/javascript/reference/global_objects/string/index.html deleted file mode 100644 index 713f9a0cb4..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/index.html +++ /dev/null @@ -1,410 +0,0 @@ ---- -title: String -slug: Web/JavaScript/Reference/Global_Objects/String -tags: - - ECMAScript 2015 - - JavaScript - - NeedsTranslation - - Reference - - String - - TopicStub -translation_of: Web/JavaScript/Reference/Global_Objects/String ---- -
{{JSRef}}
- -

L'oggetto globale "String" è un costruttore per le stringhe o una sequenza alfanumerica di caratteri.

- -

Syntax

- -

String literals take the forms:

- -
'string text'
-"string text"
-"中文 español deutsch English हिन्दी العربية português বাংলা русский 日本語 ਪੰਜਾਬੀ 한국어 தமிழ் עברית"
- -

Strings can also be created using the String global object directly:

- -
String(thing)
- -

Parametri

- -
-
thing
-
Anything to be converted to a string.
-
- -

Template literals

- -

Starting with ECMAScript 2015, string literals can also be so-called Template literals:

- -
`hello world`
-`hello!
- world!`
-`hello ${who}`
-escape `<a>${who}</a>`
- -
-
- -

Escape notation

- -

Beside regular, printable characters, special characters can be encoded using escape notation:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CodeOutput
\0the NULL character
\'single quote
\"double quote
\\backslash
\nnuova linea
\rcarriage return
\vvertical tab
\ttab
\bbackspace
\fform feed
\uXXXXunicode codepoint
\u{X} ... \u{XXXXXX}unicode codepoint {{experimental_inline}}
\xXXthe Latin-1 character
- -
-

Unlike some other languages, JavaScript makes no distinction between single-quoted strings and double-quoted strings; therefore, the escape sequences above work in strings created with either single or double quotes.

-
- -
-
- -

Long literal strings

- -

Sometimes, your code will include strings which are very long. Rather than having lines that go on endlessly, or wrap at the whim of your editor, you may wish to specifically break the string into multiple lines in the source code without affecting the actual string contents. There are two ways you can do this.

- -

You can use the + operator to append multiple strings together, like this:

- -
let longString = "This is a very long string which needs " +
-                 "to wrap across multiple lines because " +
-                 "otherwise my code is unreadable.";
-
- -

Or you can use the backslash character ("\") at the end of each line to indicate that the string will continue on the next line. Make sure there is no space or any other character after the backslash (except for a line break), or as an indent; otherwise it will not work. That form looks like this:

- -
let longString = "This is a very long string which needs \
-to wrap across multiple lines because \
-otherwise my code is unreadable.";
-
- -

Both of these result in identical strings being created.

- -

Descrizione

- -

Strings are useful for holding data that can be represented in text form. Some of the most-used operations on strings are to check their {{jsxref("String.length", "length")}}, to build and concatenate them using the + and += string operators, checking for the existence or location of substrings with the {{jsxref("String.prototype.indexOf()", "indexOf()")}} method, or extracting substrings with the {{jsxref("String.prototype.substring()", "substring()")}} method.

- -

Character access

- -

There are two ways to access an individual character in a string. The first is the {{jsxref("String.prototype.charAt()", "charAt()")}} method:

- -
return 'cat'.charAt(1); // returns "a"
-
- -

The other way (introduced in ECMAScript 5) is to treat the string as an array-like object, where individual characters correspond to a numerical index:

- -
return 'cat'[1]; // returns "a"
-
- -

For character access using bracket notation, attempting to delete or assign a value to these properties will not succeed. The properties involved are neither writable nor configurable. (See {{jsxref("Object.defineProperty()")}} for more information.)

- -

Comparing strings

- -

C developers have the strcmp() function for comparing strings. In JavaScript, you just use the less-than and greater-than operators:

- -
var a = 'a';
-var b = 'b';
-if (a < b) { // true
-  console.log(a + ' is less than ' + b);
-} else if (a > b) {
-  console.log(a + ' is greater than ' + b);
-} else {
-  console.log(a + ' and ' + b + ' are equal.');
-}
-
- -

A similar result can be achieved using the {{jsxref("String.prototype.localeCompare()", "localeCompare()")}} method inherited by String instances.

- -

Distinction between string primitives and String objects

- -

Note that JavaScript distinguishes between String objects and primitive string values. (The same is true of {{jsxref("Boolean")}} and {{jsxref("Global_Objects/Number", "Numbers")}}.)

- -

String literals (denoted by double or single quotes) and strings returned from String calls in a non-constructor context (i.e., without using the {{jsxref("Operators/new", "new")}} keyword) are primitive strings. JavaScript automatically converts primitives to String objects, so that it's possible to use String object methods for primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup.

- -
var s_prim = 'foo';
-var s_obj = new String(s_prim);
-
-console.log(typeof s_prim); // Logs "string"
-console.log(typeof s_obj);  // Logs "object"
-
- -

String primitives and String objects also give different results when using {{jsxref("Global_Objects/eval", "eval()")}}. Primitives passed to eval are treated as source code; String objects are treated as all other objects are, by returning the object. For example:

- -
var s1 = '2 + 2';             // creates a string primitive
-var s2 = new String('2 + 2'); // creates a String object
-console.log(eval(s1));        // returns the number 4
-console.log(eval(s2));        // returns the string "2 + 2"
-
- -

For these reasons, code may break when it encounters String objects when it expects a primitive string instead, although generally authors need not worry about the distinction.

- -

A String object can always be converted to its primitive counterpart with the {{jsxref("String.prototype.valueOf()", "valueOf()")}} method.

- -
console.log(eval(s2.valueOf())); // returns the number 4
-
- -
Note: For another possible approach to strings in JavaScript, please read the article about StringView — a C-like representation of strings based on typed arrays.
- -

Properties

- -
-
{{jsxref("String.prototype")}}
-
Allows the addition of properties to a String object.
-
- -

Methods

- -
-
{{jsxref("String.fromCharCode()")}}
-
Returns a string created by using the specified sequence of Unicode values.
-
{{jsxref("String.fromCodePoint()")}} {{experimental_inline}}
-
Returns a string created by using the specified sequence of code points.
-
{{jsxref("String.raw()")}} {{experimental_inline}}
-
Returns a string created from a raw template string.
-
- -

String generic methods

- -
-

String generics are non-standard, deprecated and will get removed near future. Note that you can not rely on them cross-browser without using the shim that is provided below.

-
- -

The String instance methods are also available in Firefox as of JavaScript 1.6 (not part of the ECMAScript standard) on the String object for applying String methods to any object:

- -
var num = 15;
-console.log(String.replace(num, /5/, '2'));
-
- -

{{jsxref("Global_Objects/Array", "Generics", "#Array_generic_methods", 1)}} are also available on {{jsxref("Array")}} methods.

- -

The following is a shim to provide support to non-supporting browsers:

- -
/*globals define*/
-// Assumes all supplied String instance methods already present
-// (one may use shims for these if not available)
-(function() {
-  'use strict';
-
-  var i,
-    // We could also build the array of methods with the following, but the
-    //   getOwnPropertyNames() method is non-shimable:
-    // Object.getOwnPropertyNames(String).filter(function(methodName) {
-    //   return typeof String[methodName] === 'function';
-    // });
-    methods = [
-      'quote', 'substring', 'toLowerCase', 'toUpperCase', 'charAt',
-      'charCodeAt', 'indexOf', 'lastIndexOf', 'startsWith', 'endsWith',
-      'trim', 'trimLeft', 'trimRight', 'toLocaleLowerCase',
-      'toLocaleUpperCase', 'localeCompare', 'match', 'search',
-      'replace', 'split', 'substr', 'concat', 'slice'
-    ],
-    methodCount = methods.length,
-    assignStringGeneric = function(methodName) {
-      var method = String.prototype[methodName];
-      String[methodName] = function(arg1) {
-        return method.apply(arg1, Array.prototype.slice.call(arguments, 1));
-      };
-    };
-
-  for (i = 0; i < methodCount; i++) {
-    assignStringGeneric(methods[i]);
-  }
-}());
-
- -

String instances

- -

Properties

- -
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Properties')}}
- -

Methods

- -

Methods unrelated to HTML

- -
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'Methods_unrelated_to_HTML')}}
- -

HTML wrapper methods

- -
{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype', 'HTML_wrapper_methods')}}
- -

Examples

- -

String conversion

- -

It's possible to use String as a "safer" {{jsxref("String.prototype.toString()", "toString()")}} alternative, as although it still normally calls the underlying toString(), it also works for {{jsxref("null")}}, {{jsxref("undefined")}}, and for {{jsxref("Symbol", "symbols")}}. For example:

- -
var outputStrings = [];
-for (var i = 0, n = inputValues.length; i < n; ++i) {
-  outputStrings.push(String(inputValues[i]));
-}
-
- -

Specifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificationStatusComment
{{SpecName('ES1')}}{{Spec2('ES1')}}Initial definition.
{{SpecName('ES5.1', '#sec-15.5', 'String')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string-objects', 'String')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string-objects', 'String')}}{{Spec2('ESDraft')}} 
- -

Browser compatibility

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatChrome("1")}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
\u{XXXXXX}{{CompatVersionUnknown}}{{CompatGeckoDesktop("40")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatVersionUnknown}}
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
\u{XXXXXX}{{CompatUnknown}}{{CompatUnknown}}{{CompatGeckoMobile("40")}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
-
- -

See also

- - diff --git a/files/it/web/javascript/reference/global_objects/string/indexof/index.html b/files/it/web/javascript/reference/global_objects/string/indexof/index.html deleted file mode 100644 index e8653cac62..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/indexof/index.html +++ /dev/null @@ -1,151 +0,0 @@ ---- -title: String.prototype.indexOf() -slug: Web/JavaScript/Reference/Global_Objects/String/indexOf -translation_of: Web/JavaScript/Reference/Global_Objects/String/indexOf ---- -
{{JSRef}}
- -

Il metodo indexOf() restituisce l'indice all'interno dell'oggetto {{jsxref("String")}} chiamante della prima occorrenza del valore specificato, avviando la ricerca su fromIndex. Restituisce -1 se il valore non viene trovato.

- -
{{EmbedInteractiveExample("pages/js/string-indexof.html")}}
- - - -
Note: Per il metodo dell'Array, vedere {{jsxref("Array.prototype.indexOf()")}}.
- -

Sintassi

- -
str.indexOf(searchValue[, fromIndex])
- -

Parametri

- -
-
searchValue
-
Una stringa che rappresenta il valore da cercare. Se non viene fornita esplicitamente alcuna stringa, searchValue sarà forzato a "undefined" e questo valore verrà cercato nella stringa corrente.
-
fromIndex {{optional_inline}}
-
Un numero intero che rappresenta l'indice al quale avviare la ricerca; il valore predefinito è  0. Per valori fromIndex values inferiori a 0 o maggiori di str.length, la ricerca inizia rispettivamente con 0str.length.
-
- -

Valore di ritorno

- -

L'indice della prima occorrenza di searchValue o -1 se non trovato.
- Una stringa vuota searchValue corrisponderà a qualsiasi indice tra 0 e str.length.

- -

Descrizione

- -

I caratteri in una stringa sono indicizzati da sinistra a destra. L'indice del primo carattere è 0 e l'indice dell'ultimo carattere di una stringa chiamata stringName è stringName.length - 1.

- -
'Blue Whale'.indexOf('Blue');     // ritorna  0
-'Blue Whale'.indexOf('Blute');    // ritorna -1
-'Blue Whale'.indexOf('Whale', 0); // ritorna  5
-'Blue Whale'.indexOf('Whale', 5); // ritorna  5
-'Blue Whale'.indexOf('Whale', 7); // ritorna -1
-'Blue Whale'.indexOf('');         // ritorna  0
-'Blue Whale'.indexOf('', 9);      // ritorna  9
-'Blue Whale'.indexOf('', 10);     // ritorna 10
-'Blue Whale'.indexOf('', 11);     // ritorna 10
-
- -

Il metodo indexOf() è case sensitive. Ad esempio, la seguente espressione restituisce -1:

- -
'Blue Whale'.indexOf('blue'); // ritorna -1
-
- -

Controllo delle occorrenze

- -

Nota che '0' non valuta true e '-1' non valuta false. Pertanto, quando si verifica se esiste una stringa specifica all'interno di un'altra stringa, il modo corretto per verificare sarebbe:

- -
'Blue Whale'.indexOf('Blue') !== -1; // true
-'Blue Whale'.indexOf('Bloe') !== -1; // false
-
- -

Esempi

- -

Usare indexOf()

- -

Nell'esempio seguente viene utilizzato indexOf() per individuare i valori nella stringa "Brave new world".

- -
const str = 'Brave new world';
-
-console.log('L'indice della prima w dall'inizio è ' + str.indexOf('w'));  // logga 8
-console.log('L'indice di "new" dall'inizio è ' + str.indexOf('new'));  // logga 6
-
- -

indexOf() e il case-sensitivity

- -

L'esempio seguente definisce due variabili stringa. Le variabili contengono la stessa stringa tranne che la seconda stringa contiene lettere maiuscole. Il primo metodo {{domxref("console.log()")}} mostra 19. Ma poiché il metodo indexOf() è case sensitive, la stringa "cheddar" non si trova in myCapString, quindi il secondo metodo console.log() mostra -1.

- -
const myString    = 'brie, pepper jack, cheddar';
-const myCapString = 'Brie, Pepper Jack, Cheddar';
-
-console.log('myString.indexOf("cheddar") è ' + myString.indexOf('cheddar'));
-// logs 19
-console.log('myCapString.indexOf("cheddar") è ' + myCapString.indexOf('cheddar'));
-// logs -1
-
- -

Uso di indexOf() per contare le occorrenze di una lettera in una stringa

- -

L'esempio seguente imposta count sul numero di occorrenze della lettera e nella stringa str:

- -
const str = 'Essere o non essere, questa è la domanda.';
-let count = 0;
-let position = str.indexOf('e');
-
-while (position !== -1) {
-  count++;
-  position = str.indexOf('e', position + 1);
-}
-
-console.log(count); // mostra 4
-
- -

Specifiche

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificaStatoCommento
{{SpecName('ES1')}}{{Spec2('ES1')}}Definizione iniziale.
{{SpecName('ES5.1', '#sec-15.5.4.7', 'String.prototype.indexOf')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-string.prototype.indexof', 'String.prototype.indexOf')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-string.prototype.indexof', 'String.prototype.indexOf')}}{{Spec2('ESDraft')}} 
- -

Compatibilità con i browser

- - - -

{{Compat("javascript.builtins.String.indexOf")}}

- -

Vedi anche

- - diff --git a/files/it/web/javascript/reference/global_objects/string/length/index.html b/files/it/web/javascript/reference/global_objects/string/length/index.html deleted file mode 100644 index e575b777b8..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/length/index.html +++ /dev/null @@ -1,90 +0,0 @@ ---- -title: string.length -slug: Web/JavaScript/Reference/Global_Objects/String/length -translation_of: Web/JavaScript/Reference/Global_Objects/String/length ---- -
{{JSRef}}
- -

La proprietà length di un oggetto {{jsxref("String")}} indica la lunghezza di una stringa, in unità di codice UTF-16.

- -

Sintassi

- -
str.length
- -

Descrizione

- -

Questa proprietà restituisce il numero di unità di codice nella stringa. {{interwiki("wikipedia", "UTF-16")}}, il formato di stringa utilizzato da JavaScript, utilizza una singola unità di codice a 16 bit per rappresentare i caratteri più comuni, ma deve utilizzare due unità di codice per meno comunemente- caratteri usati, quindi è possibile che il valore restituito dalla length “lunghezza“ non corrisponda al numero effettivo di caratteri nella stringa.

- -

ECMASCript 2016 (ed. 7) ha stabilito una lunghezza massima di 2^53 - 1 elementi. In precedenza, non è stata specificata una lunghezza massima.. 

- -

Per una stringa vuota, length è 0.

- -

La proprietà statica String.length restituisce il valore 1.

- -

Esempi

- -

Basic usage

- -
var x = 'Mozilla';
-var empty = '';
-
-console.log('Mozilla is ' + x.length + ' code units long');
-/* "Mozilla è lungo 7 unità di codice" */
-
-console.log('La stringa vuota ha una lunghezza di
- ' + empty.length);
-/* "La stringa vuota ha una lunghezza di 0" */
- -

Assegnazione a length

- -
var myString = "bluebells";
-
-// Il tentativo di assegnare un valore alla proprietà .length di una stringa non ha alcun effetto osservabile.
-myString.length = 4;
-console.log(myString);
-/* "bluebells" */
-
- -

Specificazioni

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
SpecificazioniStatoCommenti
{{SpecName('ES1')}}{{Spec2('ES1')}}Definizione iniziale Implementato in JavaScript 1.0.
{{SpecName('ES5.1', '#sec-15.5.5.1', 'String.prototype.length')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-properties-of-string-instances-length', 'String.prototype.length')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-properties-of-string-instances-length', 'String.prototype.length')}}{{Spec2('ESDraft')}} 
- -

Browser compatibili

- - - -

{{Compat("javascript.builtins.String.length")}}

- -

Guarda anche

- - diff --git a/files/it/web/javascript/reference/global_objects/string/raw/index.html b/files/it/web/javascript/reference/global_objects/string/raw/index.html deleted file mode 100644 index 2d070b15cb..0000000000 --- a/files/it/web/javascript/reference/global_objects/string/raw/index.html +++ /dev/null @@ -1,108 +0,0 @@ ---- -title: String.raw() -slug: Web/JavaScript/Reference/Global_Objects/String/raw -translation_of: Web/JavaScript/Reference/Global_Objects/String/raw ---- -
{{JSRef}}
- -

Il metodo statico String.raw() è una funzione di tag del modello template string, simile al prefisso r in Python o al prefisso @ in C# per i valori letterali stringa (tuttavia c'è una differenza: vedere le spiegazioni in questo numero ). È usato per ottenere la stringa di stringhe di template non formattata, cioè le sostituzioni (ad esempio ${foo}) vengono elaborate, ma gli escape (ad esempio \n ) non lo sono.

- -

Sintassi

- -
String.raw(callSite, ...substitutions)
-String.raw`templateString`
-
- -

Parametri

- -
-
callSite
-
Oggetto del sito di chiamata template ben formato, come { raw: ['foo', 'bar', 'baz'] }.
-
...substitutions
-
Contiene valori di sostituzione.
-
templateString
-
A template string, puoi sostituirlo opzionalmente (${...}).
-
- -

Valore resituto

- -

Restituisce una stringa non elaborata di un determinato Template String.

- -

Eccezioni

- -
-
{{jsxref("TypeError")}}
-
Un oggetto {{jsxref("TypeError")}} viene generato se il primo argomento non è un oggetto formato.
-
- -

Descrizione

- -

Nella maggior parte dei casi, String.raw() viene utilizzato con template strings. La prima sintassi menzionata sopra è usata solo di rado, perché il motore JavaScript la chiamerà con argomenti appropriati, proprio come con altre funzioni tag .

- -

String.raw() è l'unica funzione di built-in tag incorporata nei template strings; funziona proprio come la funzione predefinita del modello ed esegue la concatenazione. Puoi anche ri-implementarlo con il normale codice JavaScript.

- -

Esempi

- -

Utilizzo di String.raw()

- -
String.raw`Ciao\n${2+3}!`;
-// 'Ciao\n5!', Il carattere dopo 'Ciao' non è un carattere di nuova riga,
-// '\' e 'n' sono due caratteri.
-
-String.raw`Hi\u000A!`;
-// 'Ciao\u000A!', Lo stesso qui, questa volta avremo il
-// \, u, 0, 0, 0, A, 6 caratteri.
-// Tutti i tipi di caratteri di escape saranno inefficaci
-// e backslash saranno presenti nella stringa di output
-// Puoi confermare questo controllando la proprietà .length
-// della stringa.
-
-let name = 'Bob';
-String.raw`Ciao\n${name}!`;
-// 'Ciao\nBob!', le sostituzioni vengono elaborate.
-
-// Normalmente non si chiama String.raw() come una funzione,
-// ma la si chiama per simulare `t${0}e${1}s${2}t` puoi fare:
-String.raw({ raw: 'test' }, 0, 1, 2); // 't0e1s2t'
-// Nota che la stringa 'test', è un oggetto simile ad un array
-// Il seguente è equivalente a
-// `foo${2 + 3}bar${'Java' + 'Script'}baz`
-String.raw({
-  raw: ['foo', 'bar', 'baz']
-}, 2 + 3, 'Java' + 'Script'); // 'foo5barJavaScriptbaz'
- -

Specificazioni

- - - - - - - - - - - - - - - - - - - -
SpecificazioniStatoCommento
{{SpecName('ES2015', '#sec-string.raw', 'String.raw')}}{{Spec2('ES2015')}}Definizione iniziale.
{{SpecName('ESDraft', '#sec-string.raw', 'String.raw')}}{{Spec2('ESDraft')}} 
- -

Compatibilità con il browser

- - - -

{{Compat("javascript.builtins.String.raw")}}

- -

Guarda anche

- - -- cgit v1.2.3-54-g00ecf