简体   繁体   English

如何在f#中拆分字符串而不取出用于拆分的字符

[英]How to Split string in f# without taking out the caracter used to split

I'm trying to take a string like "hello world : bye world" and get ["hello world"; ":" ;"bye world"] 我正试着拿一个像"hello world : bye world"的字符串来获得["hello world"; ":" ;"bye world"] ["hello world"; ":" ;"bye world"] . ["hello world"; ":" ;"bye world"]

This is the simplest function I can think of to pass your test case. 这是我能想到的最简单的函数来传递你的测试用例。

let split (str:string) =
    str.Split ':'
    |> Seq.collect(fun x -> [":"; x.Trim()])
    |> Seq.tail
    |> Seq.toList

split "hello world : bye world" // ["hello world"; ":"; "bye world"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM