Skip to main content
Documentation

Strings

Kite supports two types of strings: double-quoted strings with interpolation and single-quoted literal strings.

String Types

Double-Quoted Strings (Interpolated)

Double-quoted strings support variable and expression interpolation:

var name     = "World"
var greeting = "Hello, ${name}!"  // "Hello, World!"

Single-Quoted Strings (Literal)

Single-quoted strings are literal - no interpolation:

var literal = 'No $interpolation here'
var pattern = '^[a-z]+$'  // Regex pattern

String Interpolation

Simple Variable Interpolation

Use $variable for simple variable references:

var name    = "Alice"
var age     = 30

var message = "Name: $name, Age: $age"
// Result: "Name: Alice, Age: 30"

Expression Interpolation

Use ${expression} for any expression:

var x       = 5
var y       = 10

var result  = "Sum: ${x + y}"
// Result: "Sum: 15"

var doubled = "Doubled: ${x * 2}"
// Result: "Doubled: 10"

Complex Expressions

var user  = { name: "Bob", age: 25 }

var info  = "User: ${user.name} is ${user.age} years old"
// Result: "User: Bob is 25 years old"

var items = [1, 2, 3]
var count = "Count: ${length(items)}"
// Result: "Count: 3"

Nested Interpolation

var prefix = "data"
var env    = "prod"
var suffix = "bucket"

var name   = "${prefix}-${env}-${suffix}"
// Result: "data-prod-bucket"

Escape Sequences

Common Escapes

SequenceResult
\\Backslash
\"Double quote
\'Single quote
\nNewline
\tTab
\$Literal dollar sign

Examples

var path          = "C:\\Users\\name"
var quoted        = "He said \"Hello\""
var literalDollar = "Price: \$100"
var multiline     = "Line 1\nLine 2"

Strings in Resources

String interpolation is commonly used in resource names and properties:

var environment = "production"
var appName     = "myapp"

resource S3.Bucket storage {
    name        = "${appName}-${environment}-storage"
    // Result: "myapp-production-storage"
}

resource EC2.Instance server {
    name        = "${appName}-server-${environment}"
    tags        = {
        Name: "${appName}-server",
        Environment: environment
    }
}

Strings with @count

The count variable is automatically available in counted resources:

@count(3)
resource EC2.Instance server {
    name = "server-${count}"
    // Creates: "server-0", "server-1", "server-2"
}

Strings in Components

component WebApp {
    input string name
    input string environment = "dev"

    resource EC2.Instance server {
        name                 = "${name}-${environment}-server"
    }

    output string endpoint   = "https://${name}.example.com"
}

component WebApp prod {
    name                     = "myapp"
    environment              = "prod"
}

// prod.endpoint = "https://myapp.example.com"

String Operations

Concatenation

var first    = "Hello"
var second   = "World"

// Using interpolation
var combined = "${first} ${second}"

// Or with + operator
var combined = first + " " + second

String Functions (Standard Library)

var text     = "Hello World"

// Length
var len      = length(text)  // 11

// Case conversion
var upper    = toUpperCase(text)  // "HELLO WORLD"
var lower    = toLowerCase(text)  // "hello world"

// Substring
var sub      = substring(text, 0, 5)  // "Hello"

// Contains
var has      = contains(text, "World")  // true

// Replace
var replaced = replace(text, "World", "Kite")  // "Hello Kite"

// Split
var parts    = split("a,b,c", ",")  // ["a", "b", "c"]

// Join
var joined   = join(["a", "b", "c"], "-")  // "a-b-c"

// Trim
var trimmed  = trim("  hello  ")  // "hello"

Multiline Strings

Single-quoted strings support multiline content:

var script = '
#!/bin/bash
echo "Hello"
echo "World"
'

For double-quoted strings, use \n:

var message = "Line 1\nLine 2\nLine 3"

String Comparison

var a = "hello"
var b = "hello"
var c = "world"

a == b  // true
a == c  // false
a != c  // true

Best Practices

Use Interpolation for Dynamic Strings

// Good
var name = "bucket-${environment}"

// Avoid
var name = "bucket-" + environment

Use Single Quotes for Patterns

// Good - no escaping needed
@validate(regex: '^[a-z0-9-]+$')
input string name

// Would need escaping with double quotes
@validate(regex: "^[a-z0-9-]+$")
input string name

Meaningful Resource Names

// Good - descriptive and unique
resource S3.Bucket storage {
    name = "${appName}-${environment}-${purpose}"
}

// Avoid - generic names
resource S3.Bucket storage {
    name = "bucket1"
}

Next: Learn about Imports - modular code organization.