Skip to content

Latest commit

 

History

History

StringPlus

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

String+

String+ is an extension for the Swift String class that provides additional functionalities for string manipulation.

Usage

Subscripting

Single Int Subscripting

let str = "Hello, World!"
let char = str[0] // Returns: "H"

Range Subscripting

Range Int subcripting

let str = "Hello, World!"
let substring = str[0..<5] // Returns: "Hello"

Custom Operator <|

The <| operator is used to return the first argument if it is not nil nor empty; otherwise, it returns the second argument.

let str1: String = ""
let str2 = "Default Value"
let result = str1 <| str2 // Returns: "Default Value"

Example

let str = "Hello, World!"
let char = str[0] // Returns: "H"
let substring = str[0..<5] // Returns: "Hello"

let str1: String? = nil
let str2 = "Default Value"
let result = str1 <| str2 // Returns: "Default Value"