xxxxxxxxxx
let str = "hello there how are you'll";
let array = [str]
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
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
const str = "Kamran";
let arr = [];
let k = 0;
for (let i of str) {
arr[k++] = i;
}
console.log(arr)
xxxxxxxxxx
String[] words = {"ace", "boom", "crew", "dog", "eon"};
List<String> wordList = Arrays.asList(words);
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;
}