I have a string obtained from a web socket:
let websocket = new ClientWebSocket()
let source = new CancellationTokenSource()
let buffer = ArraySegment(Array.zeroCreate 32)
do! websocket.ConnectAsync(url, source.Token)
do! websocket.ReceiveAsync(buffer, source.Token)
let str = Encoding.ASCII.GetString buffer.Array
let trim1 = Regex.replace str "\0" String.Empty
let trim2 = Regex.replace str "\\0" String.Empty
let trim3 = str.TrimEnd [| '\\'; '0' |]
I'm obviously trying to trim extra null characters
In the debugger, the value for str is "{\" type \ ": \" hello \ "} \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0 "
When printed, it looks like this: {"type": "hello"}, which makes sense, the characters are interpreted properly.
I can't seem to complete this simple task in f #, what am I doing wrong?
source
share