# `$` Tok


_Interpret a string as a data value_

```syntax
x$y    $[x;y]
```

Where

-   `y` is a **string**
-   `x` is a **non-positive short or upper-case char** as below (or the null symbol as a synonym for `"S"`)

returns `y` as an atom value interpreted according to `x`.

`x` values for Tok:
```q
q){([result:key'[x$\:()]];short:neg x;char:upper .Q.t x)}5h$where" "<>20#.Q.t
result   | short char
---------| ----------
boolean  | -1    B
guid     | -2    G
byte     | -4    X
short    | -5    H
int      | -6    I
long     | -7    J
real     | -8    E
float    | -9    F
char     | -10   C
symbol   | -11   S
timestamp| -12   P
month    | -13   M
date     | -14   D
datetime | -15   Z
timespan | -16   N
minute   | -17   U
second   | -18   V
time     | -19   T
```

A left argument of `0h` or `"*"` returns the `y` string unchanged.

Where `x` is a **positive or zero short**, a **lower-case char**, **`"*"`**, or a non-null **symbol**, see [Cast](cast.md).

```q
q)"E"$"3.14"
3.14e
q)-8h$"3.14"
3.14e
q)"D"$"2000-12-12"
2000.12.12
q)"U"$"12:13:14"
12:13
q)"T"$"123456789"
12:34:56.789
q)"P"$"2015-10-28D03:55:58.6542"
2015.10.28D03:55:58.654200000
```

## Outside of domain

Parsing values outside of the types domain returns null.
```q
q)"H"$"32768"
0Nh
q)"I"$"2147483648"
0Ni
q)"D"$"2147483648"
0Nd
```

> **Note — Changes since 4.1t 2021.09.03,4.0 2021.10.01**
>
>
> Short converts to 0Nh instead of +/-0Wh 
>
## Iteration

Tok is a near-[atomic function](../basics/atomic.md).
Implicit recursion stops at strings, not atoms.
```q
q)"BXH"$("42";"42";"42")
0b
0x42
42h

q)("B";"XHI")$("42";("42";"42";"42"))
0b
(0x42;42h;42i)

q)"B"$"   Y  "
1b
q)"B"$'"   Y  "
000100b
```


## Symbols

!!! tip Use "Use the null symbol as a shorthand left argument for `"S"`."
```q
q)"S"$"hello"
`hello
q)`$"hello"
`hello
```

Converting a string to a symbol removes leading and trailing blanks.
```q
q)`$"   IBM   "
`IBM
```


## Truthy characters

Certain characters are recognized as boolean True:
```q
q)"B"$(" Y ";"    N ")
10b
q)" ",.Q.an
" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789"
q)"B"$'" ",.Q.an
0000000000000000000010001100000000000000000000100011000100000000b

q).Q.an where"B"$'.Q.an
"txyTXY1"
```

Contrast this with [casting to boolean](cast.md#boolean):
```q
q)"b"$" ",.Q.an
1111111111111111111111111111111111111111111111111111111111111111b
```


## IP address

### IPv4 address as int
```q
q)"I"$"192.168.1.34" /an IP address as an int
-1062731486i
```

[`.Q.addr`](dotq.md#addr-iphost-as-int) (IP/host as int),
[`.Q.host`](dotq.md#host-ip-to-hostname) (IP to hostname)

### IPv4 address as guid

Available since 3.6 2017.09.26.
```q
q)"G"$"192.0.2.1"
00000000-0000-0000-0000-ffffc0000201
```

### IPv6 address as guid

Available since 3.6 2017.09.26.
```q
q)"G"$"2001:0DB8:85A3:0000:0000:8A2E:0370:7334"
20010db8-85a3-0000-0000-8a2e03707334
q)"G"$"2001:0DB8:85A3::8A2E:0370:7334"
20010db8-85a3-0000-0000-8a2e03707334
q)"G"$"::8A2E:0370:7334"
00000000-0000-0000-0000-8a2e03707334
```

Representations of an IPv4 address using IPv6 formatting:
```q
q)"G"$"::FFFF:192.0.2.1"
00000000-0000-0000-0000-ffffc0000201
q)"G"$"::FFFF:c000:201"
00000000-0000-0000-0000-ffffc0000201
q)"G"$"192.0.2.1"
00000000-0000-0000-0000-ffffc0000201
```

## Timestamps

### Raw numeric timestamps
```q
q)"N"$"123456123987654"
0D12:34:56.123987654
q)"T"$"123456123987654"
12:34:56.123
```

### Unix timestamps

(from seconds since Unix epoch), string with 9…11 digits:
```q
q)"P"$"10129708800"
2290.12.31D00:00:00.000000000
q)"P"$"00000000000"
1970.01.01D00:00:00.000000000
```

If these digits are followed by a `.` Tok will parse what follows `.` as parts of second, e.g.
```q
q)"P"$"10129708800.123456789"
2290.12.31D00:00:00.123456789
q)"P"$"00000000000.123456789"
1970.01.01D00:00:00.123456789

q)"PZ"$\:"20191122-11:11:11.123"
2019.11.22D11:11:11.123000000
2019.11.22T11:11:11.123
```

## Date formats

`"D"$` will Tok dates with varied formats:
```txt
[yy]yymmdd
ddMMM[yy]yy
yyyy/[mm|MMM]/dd
[mm|MMM]/dd/[yy]yy  / when \z is set to 0 (default)
dd/[mm|MMM]/[yy]yy  / when \z is set to 1
```


[Command-line option `-z` (date format)](../basics/cmdline.md#-z-date-format)


[System command `\z` (date format)](../basics/syscmds.md#z-date-parsing)

----

[Cast](cast.md)


[Overloads of `$`](overloads.md#dollar)


[`.h.iso8601`](doth.md#hiso8601-iso-timestamp) ISO 8601 timestamp


[Casting](../basics/by-topic.md#casting-and-encoding)


_Q for Mortals_
[§7.3.3 Parsing Data from Strings](/q4m3/7_Transforming_Data/#733-parsing-data-from-strings)
