C # I can use string.Join("", lines)to convert a string array to a string. What can I do to do the same with F #?
ADDED
I need to read lines from a file, perform some operation, and then combine all the lines into one line.
When i run this code
open System.IO
open String
let lines =
let re = System.Text.RegularExpressions.Regex(@"#(\d+)")
[|for line in File.ReadAllLines("tclscript.do") ->
re.Replace(line.Replace("{", "{{").Replace("}", "}}").Trim(), "$1", 1)|]
let concatenatedLine = String.Join("", lines)
File.WriteAllLines("tclscript.txt", concatenatedLine)
I got this error
error FS0039: The value or constructor 'Join' is not defined
I tried this code let concatenatedLine = lines |> String.concat ""to get this error
error FS0001: This expression was expected to have type
string []
but here has type
string
Decision
open System.IO
open System
let lines =
let re = System.Text.RegularExpressions.Regex(@"#(\d+)")
[|for line in File.ReadAllLines("tclscript.do") ->
re.Replace(line.Replace("{", "{{").Replace("}", "}}"), "$1", 1) + @"\n"|]
let concatenatedLine = String.Join("", lines)
File.WriteAllText("tclscript.txt", concatenatedLine)
and this one also works.
let concatenatedLine = lines |> String.concat ""
source
share