Actually the function is already in String :
let multiply text times = String.replicate times text
To write your own function, an efficient way is to use StringBuilder
:
open System.Text let multiply (text: string) times = let sb = new StringBuilder() for i in 1..times do sb.Append(text) |> ignore sb.ToString()
If you want to remove trailing spaces, as in your example, you can use the Trim()
member in the String
class to do this.
source share