# `vs`

_“Vector from scalar”_

-   _partition a symbol, string, or bytestream_
-   _encode a vector from an atom, or a matrix from a vector_
```syntax
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
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 bytestream by linebreak

Where `x` is the empty symbol `` ` ``, and `y` is a string or bytestream, returns as a list of strings `y` partitioned on embedded line terminators into lines. (Recognizes both Unix `\n` and Windows `\r\n` terminators).
```q
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"
```

> **Detail — Elides trailing linebreaks**
>
>
> The treatment of linebreaks varies usefully from a left argument of `\n`.
>
> ```q
> 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 as a symbol vector `y` split on `` `.` ``.
```q
q)` vs `mywork.dat
`mywork`dat
```


### File handle

Where `x` is the empty symbol `` ` ``, and `y` is a file handle, returns as a symbol vector `y` split into directory and  file parts.
```q
q)` vs `:/home/kdb/data/mywork.dat
`:/home/kdb/data`mywork.dat
```


[sv](sv.md#join) join


### Byte Vectors

Since 4.1t 2024.01.11, `y` can be a byte vector: y cut using x as the delimiter.
```q
q)0x02 vs 0x0102010201
,0x01
,0x01
,0x01
q)0x0203 vs 0x000102030405
0x0001
0x0405
q)" "vs"x"$"a b"    / type inferred from left hand side
,"a"
,"b"
```


## Encode


### Bit representation

Where `x` is `0b` and `y` is an integer, returns the bit representation of `y`.
```q
q)0b vs 23173h
0101101010000101b
q)0b vs 23173i
00000000000000000101101010000101b
```

Since 4.1t 2021.09.03, `y` also supports guids.
```q
q)0b vs rand 0Ng
10001100011010111000101101100100011010000001010101100000100001000000101000111110000101111000010000000001001001010001101101101000b
```

### Byte representation

Where `x` is `0x0` and `y` is a number, returns the internal representation of `y`, with each byte in hex.
```q
q)0x0 vs 2413h
0x096d
q)0x0 vs 2413i
0x0000096d
q)0x0 vs 2413e
0x4516d000
q)0x0 vs 2413f
0x40a2da0000000000
```

#### Integer based IP address

Base-256 is used to encode IP addresses to integers. The following example converts the current IP address reported by [`.z.a`](dotz.md#za-ip-address)
```q
q)"i"$0x0 vs .z.a
192 168 0 3i
```
The commonly written dotted-decimal notation can be produced from the list of longs using [`string`](string.md) and [`sv`](sv.md#strings).
```q
q)"." sv string "i"$0x0 vs .z.a
"192.168.0.3"
```

### Base-x representation

Where `x` and `y` are integer, the result is the representation of `y` in base `x`. (Since V3.4t 2015.12.13.)
```q
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 .z.a / ip address string from .z.a
"192.168.1.213"
```

Where `y` is an integer vector the result is a matrix with `count[x]` items whose `i`-th column `(x vs y)[;i]` is identical to `x vs y[i]`.
More generally, `y` can be any list of integers, and each item of the result is identical to `y` in structure.
```q
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
```

---

[`sv`](sv.md#decode) decode


[`.Q.j10`](dotq.md#j10-encode-binhex) encode binhex, 
[`.Q.j12`](dotq.md#j12-encode-base-36) encode base36


[`.Q.x10`](dotq.md#x10-decode-binhex) decode binhex,
[`.Q.x12`](dotq.md#x12-decode-base-36) decode base36
