xxxxxxxxxx
public List<string> ArrayFromString(string str)
{
var sb = new StringBuilder();
var ls = new List<string>();
for (int i = 0; i < str.Length; i++)
{
if(str[i]>=65 && str[i]<=90 || str[i]>=97 && str[i]<=122)
sb.Append(str[i]);
else
{
if(sb.Length>0)
ls.Add(sb.ToString());
sb.Clear();
}
}
if(sb.Length>0)
{
ls.Add(sb.ToString());
}
return ls;
}
xxxxxxxxxx
// our string
let string = 'ABCDEFG';
// splits every letter in string into an item in our array
let newArray = string.split('');
console.log(newArray); // OUTPUTS: [ "A", "B", "C", "D", "E", "F", "G" ]
xxxxxxxxxx
const str = 'Hello!';
console.log(Array.from(str)); // ["H", "e", "l", "l", "o", "!"]
xxxxxxxxxx
var myString = 'no,u';
var MyArray = myString.split(',');//splits the text up in chunks
xxxxxxxxxx
services = "['service1', 'service2', 'service3']"
services = services.replace(/'/g, '"') //replacing all ' with "
services = JSON.parse(services)
console.log(services)
xxxxxxxxxx
let string = "Hello World!"
let arr = string.split(' '); // returns ["Hello","World!"]
let arr = string.split(''); // returns ["H","e","l","l"," ","W","o","r","l","d","!"]
let string = "Apple, Orange, Pear, Grape"
let arr = string.split(','); // returns ["Apple","Orange","Pear","Grape"]
xxxxxxxxxx
str = 'How are you doing today?';
console.log(str.split(' '));
>> (5) ["How", "are", "you", "doing", "today?"]
xxxxxxxxxx
var a = "['a', 'b', 'c']";
a = a.replace(/'/g, '"');
a = JSON.parse(a);
xxxxxxxxxx
var fruits = 'apple, orange, pear, banana, raspberry, peach';
var ar = fruits.split(', '); // split string on comma space
console.log( ar );
// [ "apple", "orange", "pear", "banana", "raspberry", "peach" ]
xxxxxxxxxx
// Designed by shola for shola
str = 'How are you doing today?';
console.log(str.split(" "));
//try console.log(str.split("")); with no space in the split function
//try console.log(str.split(",")); with a comma in the split function