# Binary strings

```ruby
# string creation
var x = "hello world"

# string destruction
x = nil

# string assignment with a null byte
x = "a\0b"
say x.length  # ==> 3

# string comparison
if (x == "hello") {
  say "equal"
} else {
  say "not equal"
}

var y = 'bc'
if (x < y) {
  say "#{x} is lexicographically less than #{y}"
}

# string cloning
var xx = x.clone
say (x == xx)                  # true, same length and content
say (x.refaddr == xx.refaddr)  # false, different objects

# check if empty
if (x.is_empty) {
  say "is empty"
}

# append a byte
x += "\07"
say x.dump                  #=> "a\0b\a"

# substring
say x.substr(0, -1).dump    #=> "a\0b"

# replace bytes
say "hello world".tr("l", "L")

# join strings
var a = "hel"
var b = "lo w"
var c = "orld"
var d = (a + b + c)
say d
```

#### Output:

```
3
not equal
ab is lexicographically less than bc
true
true
"a\0b\a"
"a\0b"
heLLo worLd
hello world
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/b/binary_strings.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
