转换seq< string>到F#中的string [] [英] Converting seq<string> to string[] in F#

查看:75
本文介绍了转换seq< string>到F#中的string []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章中的示例有一个示例

open System.IO

let lines = 
  File.ReadAllLines("tclscript.do")
  |> Seq.map (fun line ->
      let newLine = line.Replace("{", "{{").Replace("}", "}}")
      newLine )

File.WriteAllLines("tclscript.txt", lines)

在编译时出现错误.

error FS0001: This expression was expected to have type
    string []    
but here has type
    seq<string> 

如何将seq转换为string []以删除此错误消息?

How to convert seq to string[] to remove this error message?

推荐答案

基于Jaime的答案,由于ReadAllLines()返回一个数组,因此只需使用Array.map而不是Seq.map

Building on Jaime's answer, since ReadAllLines() returns an array, just use Array.map instead of Seq.map

open System.IO

let lines = 
  File.ReadAllLines("tclscript.do")
  |> Array.map (fun line ->
      let newLine = line.Replace("{", "{{").Replace("}", "}}")
      newLine )

File.WriteAllLines("tclscript.txt", lines)

这篇关于转换seq&lt; string&gt;到F#中的string []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆