vs¶
Vector from scalar
- Partition a symbol, string, or byte list
- Encode an atom into a vector, or a vector into a matrix
x vs y vs[x;y]
Partition¶
String by char¶
Where x is a char atom or string, and y is a string, returns a list of strings: y cut using x as the delimiter.
q)"," vs "one,two,three"
"one"
"two"
"three"
q)", " vs "spring, summer, autumn, winter"
"spring"
"summer"
"autumn"
"winter"
q)"|" vs "red|green||blue"
"red"
"green"
""
"blue"
String or byte list by line break¶
Where x is the null symbol `, and y is a string or byte list, returns y split into lines on its line terminators, as a list of strings. vs recognizes both Unix \n and Windows \r\n terminators.
q)` vs "abc\ndef\nghi"
"abc"
"def"
"ghi"
q)` vs "x"$"abc\ndef\nghi"
"abc"
"def"
"ghi"
q)` vs "abc\r\ndef\r\nghi"
"abc"
"def"
"ghi"
Ignores a trailing line break
Unlike a left argument of "\n", a null symbol ignores a final line terminator.
q)"\n" vs "abc\ndef\nghi\n"
"abc"
"def"
"ghi"
""
q)` vs "abc\ndef\nghi\n"
"abc"
"def"
"ghi"
Symbol by dot¶
Where x is the null symbol `, and y is a symbol, returns y split on `.` as a symbol vector.
q)` vs `mywork.dat
`mywork`dat
File handle¶
Where x is the null symbol `, and y is a file handle, returns y split into directory and file parts as a symbol vector.
q)` vs `:/home/kdb/data/mywork.dat
`:/home/kdb/data`mywork.dat
sv join
Byte vectors¶
Since 4.1t 2024.01.11, y can be a byte vector. Where y is a byte vector, and x is a byte or char atom or vector, returns y cut using x as the delimiter. The items of the result have the type of x.
q)0x02 vs 0x0102010201
,0x01
,0x01
,0x01
q)0x0203 vs 0x000102030405
0x0001
0x0405
q)" "vs"x"$"a b" / type inferred from left argument
,"a"
,"b"
Encode¶
Bit representation¶
Where x is 0b and y is a boolean, byte, integer, or GUID atom, returns the bit representation of y. (Since 4.1t 2021.09.03, y can be a GUID.)
q)0b vs 23173h
0101101010000101b
q)0b vs 23173i
00000000000000000101101010000101b
q)0b vs "G"$"8c6b8b64-6815-6084-0a3e-178401251b68"
10001100011010111000101101100100011010000001010101100000100001000000101000111110000101111000010000000001001001010001101101101000b
Byte representation¶
Where x is 0x0 and y is a number or GUID, returns the internal representation of y.
q)0x0 vs 2413h
0x096d
q)0x0 vs 2413i
0x0000096d
q)0x0 vs 2413e
0x4516d000
q)0x0 vs 2413f
0x40a2da0000000000
Integer-based IP address¶
IP addresses are encoded as integers in base 256. The following example converts an IP address in the integer form reported by .z.a.
q)ip:-1062731773i / for example, ip:.z.a
q)"i"$0x0 vs ip
192 168 0 3i
You can produce the commonly written dotted-decimal notation from this list using string and sv.
q)"." sv string "i"$0x0 vs ip
"192.168.0.3"
Base-x representation¶
Where x and y are integers, the result is the representation of y in base x. (Since V3.4t 2015.12.13.)
q)10 vs 1995
1 9 9 5
q)2 vs 9
1 0 0 1
q)24 60 60 vs 3805
1 3 25
q)"." sv string 256 vs ip / IP address string from integer
"192.168.0.3"
Where y is an integer vector, the result is a matrix whose i-th column (x vs y)[;i] is x vs y[i], padded with leading zeros where necessary.
More generally, y can be any list of integers, and each item of the result is identical to y in structure.
q)a:10 vs 1995 1996 1997
q)a
1 1 1
9 9 9
9 9 9
5 6 7
q)a[;0]
1 9 9 5
q)10 vs(1995;1996 1997)
1 1 1
9 9 9
9 9 9
5 6 7
q)10 vs 1995 7
1 0
9 0
9 0
5 7
sv decode