Swift Tutorial

Swift Strings & Text

Source: Bro Code

Working with Strings

Strings are sequences of characters used for names, messages, URLs, and user-facing text. In Swift, string handling is one of the most common daily tasks.

Common Operations

  • Concatenation — combine strings together
  • Interpolation — embed variables inside strings
  • Length — count characters
  • Search — find substrings or check contains
  • Transform — uppercase, lowercase, trim whitespace
SWIFT
// String operations in swift
Tip: Always validate and sanitize user input strings before displaying in HTML to prevent XSS.

Frequently Asked Questions

How do I check if a string is empty in Swift?+

Compare length to zero or check for empty string after trimming whitespace. Never rely on truthy checks alone across languages.