Introduction
Welcome to the documentation for the StringContainsOperators library. This library provides a set of operators to check if a string contains specific substrings or patterns. Whether you are working on a iOS, macOS, or tvOS project, this library makes it easy to perform string containment check operations efficiently.
Installation
To install the StringContainsOperators library in your project, you can use CocoaPods. Simply add the following line to your project’s Podfile:
pod 'StringContainsOperators'
Usage
After installing the library, you can start using the StringContainsOperators operators in your code. The library provides multiple operators that allow you to check if a string contains a specific substring or pattern. Below are some examples of the available operators and their usage:
Contains
The contains operator checks if a string contains a specific substring. It returns a boolean value indicating whether the substring is present or not.
let string = "Hello World"
if string ~= "Hello" {
print("Substring found!")
}
In the above example, the contains operator (~=) is used to check if the string “Hello” is present in the variable string. If the substring is found, the message “Substring found!” will be printed.
ContainsIgnoringCase
The containsIgnoringCase operator is similar to the contains operator, but it performs a case-insensitive check. It also returns a boolean value indicating whether the substring is present or not.
let string = "Hello World"
if string ?= "hello" {
print("Substring found ignoring case!")
}
In the above example, the containsIgnoringCase operator (?=) is used to check if the string “hello” is present in the variable string, ignoring case sensitivity. If the substring is found, the message “Substring found ignoring case!” will be printed.
HasPrefix
The hasPrefix operator checks if a string starts with a specific substring. It returns a boolean value indicating whether the prefix is present or not.
let string = "Hello World"
if string .*= "Hello" {
print("String starts with Hello!")
}
In the above example, the hasPrefix operator (.*=) is used to check if the string starts with the substring “Hello”. If the prefix is found, the message “String starts with Hello!” will be printed.
HasSuffix
The hasSuffix operator checks if a string ends with a specific substring. It returns a boolean value indicating whether the suffix is present or not.
let string = "Hello World"
if string =*. "World" {
print("String ends with World!")
}
In the above example, the hasSuffix operator (=*.) is used to check if the string ends with the substring “World”. If the suffix is found, the message “String ends with World!” will be printed.
Conclusion
The StringContainsOperators library provides a convenient way to perform string containment checks in your iOS, macOS, or tvOS projects. The various operators allow you to check for specific substrings, patterns, prefixes, and suffixes efficiently. Install the library using CocoaPods and start using these operators in your code for hassle-free string containment checks.