1 people like it.
Like the snippet!
escaping string
escaping string, very terse . Update: a bit more terse, and perf improvement by using .ToCharArray() and Array.iter
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
|
open System.Text
let escape_string (str : string) =
let buf = StringBuilder(str.Length)
let replaceOrLeave c =
match c with
| '\r' -> buf.Append "\\r"
| '\n' -> buf.Append "\\n"
| '\t' -> buf.Append "\\t"
| '"' -> buf.Append "\\\""
| _ -> buf.Append c
str.ToCharArray() |> Array.iter (replaceOrLeave >> ignore)
buf.ToString()
|
namespace System
namespace System.Text
val escape_string : str:string -> string
Full name: Script.escape_string
val str : string
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
val buf : StringBuilder
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
--------------------
StringBuilder() : unit
StringBuilder(capacity: int) : unit
StringBuilder(value: string) : unit
StringBuilder(value: string, capacity: int) : unit
StringBuilder(capacity: int, maxCapacity: int) : unit
StringBuilder(value: string, startIndex: int, length: int, capacity: int) : unit
property System.String.Length: int
val replaceOrLeave : (char -> StringBuilder)
val c : char
StringBuilder.Append(value: char []) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: obj) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: uint64) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: uint32) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: uint16) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: decimal) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: float) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: float32) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: int64) : StringBuilder
(+0 other overloads)
StringBuilder.Append(value: int) : StringBuilder
(+0 other overloads)
System.String.ToCharArray() : char []
System.String.ToCharArray(startIndex: int, length: int) : char []
module Array
from Microsoft.FSharp.Collections
val iter : action:('T -> unit) -> array:'T [] -> unit
Full name: Microsoft.FSharp.Collections.Array.iter
val ignore : value:'T -> unit
Full name: Microsoft.FSharp.Core.Operators.ignore
StringBuilder.ToString() : string
StringBuilder.ToString(startIndex: int, length: int) : string
More information