48 people like it.

Byte literals

Demonstrates an array initialized from byte literals, which use the 'uy' suffix, and an array initialized from a string byte array literal

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
open System.Text

let printBytes b =
    printfn "%s" (Encoding.ASCII.GetString(b))

let bytes = [| 104uy; 101uy; 108uy; 108uy; 111uy |]
printBytes bytes // prints "hello"

let bytes2 = "hello"B
printBytes bytes2 // also prints "hello"
namespace System
namespace System.Text
val printBytes : b:byte [] -> unit

Full name: Script.printBytes
val b : byte []
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
type Encoding =
  member BodyName : string
  member Clone : unit -> obj
  member CodePage : int
  member DecoderFallback : DecoderFallback with get, set
  member EncoderFallback : EncoderFallback with get, set
  member EncodingName : string
  member Equals : value:obj -> bool
  member GetByteCount : chars:char[] -> int + 3 overloads
  member GetBytes : chars:char[] -> byte[] + 5 overloads
  member GetCharCount : bytes:byte[] -> int + 2 overloads
  ...

Full name: System.Text.Encoding
property Encoding.ASCII: Encoding
Encoding.GetString(bytes: byte []) : string
Encoding.GetString(bytes: byte [], index: int, count: int) : string
val bytes : byte []

Full name: Script.bytes
val bytes2 : byte []

Full name: Script.bytes2

More information

Link:http://fssnip.net/3m
Posted:13 years ago
Author:Tim Robinson
Tags: byte , literal