---
# System prepended metadata

title: Strings
tags: [Guide To Contibuting]

---

###### tags: `Guide To Contibuting`

# Strings

Hey, read this! This section is somewhat sparse because **this explains everything to a good degree already.**
https://secure.byond.com/docs/ref/index.html#/DM/text

- A string is a series of characters. To you, dear viewer, consider them "fancy programmer word for a bit of text".
- String comparison using == is ridiculously fast because BYOND has a concept called a "string tree" that ensures comparing strings like this is just a memory reference/location check, which is basically checking if two numbers are equal.
- Strings can be used as indices in lists.

tl;dr

```DM

var/whatever = "This is some text"
var/docstring = {"
This is a document string
Newlines still work but embedded expressions still work too, like this:
The current world tick usage is [world.tick_usage]"}
var/hey = "Welcome! The current time is \[[time2text(world.timeofday)]]"
```
This doesn't include how to use raw strings - read the ref, you usually won't need them.
`hey` prints "Welcome! The current time is \[whatever time time2text gave]".
\[\]s signify **embedded text expressions.** Whatever inside is converted to string as best as BYOND can - more on that later.
The \\\[ is to **escape** a \[, so that \[time] shows up instead of just you getting a compile error. Escaped characters include \n for newline, \t for tab, etc. In \['s case it signifies "inject a literal \[", not start a text expression.

## String Procs
There's a bunch
`copytext`
`replacetext`
`findtext`
etc.
Read the BYOND ref, linked in the introduction. We won't cover them all because the ref has a far better description of them and what strings are in general.

## Regex
*Feel free to skip over this if you don't want to have a headache.*
Many string procs like find, replace, etc support regexes.
This is a very powerful tool allowing for what's basically patterned/fuzzy matching and manipulation of text.
Use these:
https://regexr.com/
http://regextutorials.com/
And here's how to actually use them in DM.
https://secure.byond.com/docs/ref/index.html#/{notes}/regex

Example:
`var/regex/R = regex("^([A-Za-z0-9\s]+) says, \")`
`R.Replace(text, "Meme says, \""`
(This regex may or may not be working/valid for parsing people's say logs, I haven't tested it.)

## Text macros
- Read the ref
- tl;dr:

You can do things like `\the`, `\he`, `\improper`, etc, to make BYOND do special things. Read the ref for what each one does, these are usually put before an embedded text expression to an object to manipulate how BYOND renders that object to text.

## Text conversion - Embedded Text Expressions
\[]s are nice. They convert things inside them to a string and inject them into your text where you put it.

The rules are:
- If it's an object, it reads its `name` variable and puts it in. If you have text macros in the name or before the expression, behavior might change a bit.
- If it doesn't **have** a name variable (only /atoms do, /datums don't unless you define one on them) it'll render as the type path of the object.
- If it's a number, it's converted to the text representation with around 6 figures of precision. If you need higher precision, use `num2text()`.
- If it's text it's just injected in.
- If it's a null you get nothing. It'll be as if the \[] doesn't even exist. 

## HTML Tags
This is a little advanced for so early on, so there'll be far more regarding this later.
tl;dr on our codebase most text outputs support HTML if it's going to someone's chat.
You can do `<b>Bold</b, <i>Italics</i>, <u>Underline</u>, <span class='warning'>Formatted warning</span>` and more. Don't worry about it for now, though.
