Cortar String en Arreglo / Split string into an array

/*We can easily extract substrings by using componentsSeparatedByString and specifying the character(s) that is separating them. In this example, city names are separated by a comma.*/ var myString = "Berlin, Paris, New York, San Francisco" var myArray = myString.componentsSeparatedByString(",") //Returns an array with the following values: ["Berlin", " Paris", " New York", " San Francisco"] /*Alternate Example: Notice in this example that myArray specifically creates an array that can only hold strings.*/ var myString = "Here is my string" var myArray : [String] = myString.componentsSeparatedByString(" ") //Returns a string array with the following values: ["Here", "is", "my", "string"]

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.