With C#, I can use string.Join("", lines)
to convert string array to string.
What can I do to do the same thing with F#?
I need to read lines from a file, do some operation, and then concatenate all the lines into a single 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
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 ""