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 patternString Interpolation
Simple Variable Interpolation
Use $variable for simple variable references:
var name = "Alice"var age = 30var message = "Name: $name, Age: $age"// Result: "Name: Alice, Age: 30"Expression Interpolation
Use ${expression} for any expression:
var x = 5var y = 10var 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
| Sequence | Result |
|---|---|
\\ | Backslash |
\" | Double quote |
\' | Single quote |
\n | Newline |
\t | Tab |
\$ | 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 interpolationvar combined = "${first} ${second}"// Or with + operatorvar combined = first + " " + secondString Functions (Standard Library)
var text = "Hello World"// Lengthvar len = length(text) // 11// Case conversionvar upper = toUpperCase(text) // "HELLO WORLD"var lower = toLowerCase(text) // "hello world"// Substringvar sub = substring(text, 0, 5) // "Hello"// Containsvar has = contains(text, "World") // true// Replacevar replaced = replace(text, "World", "Kite") // "Hello Kite"// Splitvar parts = split("a,b,c", ",") // ["a", "b", "c"]// Joinvar joined = join(["a", "b", "c"], "-") // "a-b-c"// Trimvar trimmed = trim(" hello ") // "hello"Multiline Strings
Single-quoted strings support multiline content:
var script = '#!/bin/bashecho "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 // truea == c // falsea != c // trueBest Practices
Use Interpolation for Dynamic Strings
// Goodvar name = "bucket-${environment}"// Avoidvar name = "bucket-" + environmentUse 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 nameMeaningful Resource Names
// Good - descriptive and uniqueresource S3.Bucket storage { name = "${appName}-${environment}-${purpose}"}// Avoid - generic namesresource S3.Bucket storage { name = "bucket1"}Next: Learn about Imports - modular code organization.