core :: Bytes :: split_once_on
self
in two parts at the first occurence of b
var a = "String is string".to_bytes.split_once_on(u's')
assert a[0].hexdigest == "537472696E672069"
assert a[1].hexdigest == "20737472696E67"
# Splits `self` in two parts at the first occurence of `b`
#
# var a = "String is string".to_bytes.split_once_on(u's')
# assert a[0].hexdigest == "537472696E672069"
# assert a[1].hexdigest == "20737472696E67"
fun split_once_on(b: BytePattern): Array[Bytes] do
var spl = b.first_index_in(self)
if spl == -1 then return [clone]
var ret = new Array[Bytes].with_capacity(2)
ret.add(slice(0, spl))
ret.add(slice_from(spl + b.pattern_length))
return ret
end
lib/core/bytes.nit:676,2--688,4