Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I split a string into a List of chars in F sharp

Tags:

How do I split string into a list of chars in F sharp for example if I want to split the word "Hello" into a list of chars ie.

"Hello" ->['H';'e';'l';'l';'o'] 

I have tried Split([| |]) but it only splits a string depending on the parameter u pass in.

I have tried this to but it still did not work

let splitChar (text:string) =      [for c in text ->c]   let splitChar (text:string) =      [for c in text do yield c]  
like image 532
Ivan Avatar asked Aug 25 '17 10:08

Ivan


People also ask

How do I split a string into substring?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.

How do I split a string into two parts in C #?

In C, the strtok() function is used to split a string into a series of tokens based on a particular delimiter. A token is a substring extracted from the original string.

How split a string by space in C#?

C# split string by multiple characters C# allows to split a string by using multiple separators. var text = "falcon;eagle,forest,sky;cloud,water,rock;wind"; var words = text. Split(new char[] {',', ';'}); Array. ForEach(words, Console.


1 Answers

You can use Seq.toList to convert a string to a list of characters:

Seq.toList "Hello" 
like image 164
Chad Gilbert Avatar answered Sep 24 '22 12:09

Chad Gilbert