Skip to content

Instantly share code, notes, and snippets.

@changtimwu
Created November 7, 2012 03:29
Show Gist options
  • Select an option

  • Save changtimwu/4029434 to your computer and use it in GitHub Desktop.

Select an option

Save changtimwu/4029434 to your computer and use it in GitHub Desktop.
strip chars after '\0'
dataary = [65,66,67,68,69,70, 0, 0, 0, 71]
buf = new Buffer(dataary)
console.log 'buf=',buf
s= buf.toString('utf-8')
console.log "s='#{s}'. length=#{s.length}"
ahash =
m1:1
m2:2
s: s
console.log ahash
s= s[..s.indexOf('\0')-1]
console.log "s='#{s}'. length=#{s.length}"
ahash.s = s
console.log ahash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment