8 people like it.

String repeater

A function that efficiently creates a new string containing a given string multiple times. The function is implemented using .NET StringBuilder class.

1: 
2: 
3: 
4: 
5: 
6: 
7: 
8: 
9: 
let stringRepeat n input =
  if System.String.IsNullOrEmpty input then
    input

  else
    let result = new System.Text.StringBuilder(input.Length * n)
    result.Insert(0, input, n).ToString()

"-" |> stringRepeat 10
val stringRepeat : n:int -> input:string -> string

Full name: Script.stringRepeat
val n : int
val input : string
namespace System
Multiple items
type String =
  new : value:char -> string + 7 overloads
  member Chars : int -> char
  member Clone : unit -> obj
  member CompareTo : value:obj -> int + 1 overload
  member Contains : value:string -> bool
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EndsWith : value:string -> bool + 2 overloads
  member Equals : obj:obj -> bool + 2 overloads
  member GetEnumerator : unit -> CharEnumerator
  member GetHashCode : unit -> int
  ...

Full name: System.String

--------------------
System.String(value: nativeptr<char>) : unit
System.String(value: nativeptr<sbyte>) : unit
System.String(value: char []) : unit
System.String(c: char, count: int) : unit
System.String(value: nativeptr<char>, startIndex: int, length: int) : unit
System.String(value: nativeptr<sbyte>, startIndex: int, length: int) : unit
System.String(value: char [], startIndex: int, length: int) : unit
System.String(value: nativeptr<sbyte>, startIndex: int, length: int, enc: System.Text.Encoding) : unit
System.String.IsNullOrEmpty(value: string) : bool
val result : System.Text.StringBuilder
namespace System.Text
Multiple items
type StringBuilder =
  new : unit -> StringBuilder + 5 overloads
  member Append : value:string -> StringBuilder + 18 overloads
  member AppendFormat : format:string * arg0:obj -> StringBuilder + 4 overloads
  member AppendLine : unit -> StringBuilder + 1 overload
  member Capacity : int with get, set
  member Chars : int -> char with get, set
  member Clear : unit -> StringBuilder
  member CopyTo : sourceIndex:int * destination:char[] * destinationIndex:int * count:int -> unit
  member EnsureCapacity : capacity:int -> int
  member Equals : sb:StringBuilder -> bool
  ...

Full name: System.Text.StringBuilder

--------------------
System.Text.StringBuilder() : unit
System.Text.StringBuilder(capacity: int) : unit
System.Text.StringBuilder(value: string) : unit
System.Text.StringBuilder(value: string, capacity: int) : unit
System.Text.StringBuilder(capacity: int, maxCapacity: int) : unit
System.Text.StringBuilder(value: string, startIndex: int, length: int, capacity: int) : unit
property System.String.Length: int
System.Text.StringBuilder.Insert(index: int, value: obj) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Insert(index: int, value: uint64) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Insert(index: int, value: uint32) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Insert(index: int, value: uint16) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Insert(index: int, value: decimal) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Insert(index: int, value: float) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Insert(index: int, value: float32) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Insert(index: int, value: int64) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Insert(index: int, value: int) : System.Text.StringBuilder
   (+0 other overloads)
System.Text.StringBuilder.Insert(index: int, value: char []) : System.Text.StringBuilder
   (+0 other overloads)

More information

Link:http://fssnip.net/30
Posted:6 years ago
Author:fholm
Tags: string .net