---
title: "#203: Simplifying Common String Operations with SwiftString 📝"
url: https://littlebitesofcocoa.com/203-simplifying-common-string-operations-with-swiftstring
author: Jake Marsh
published: 2016-03-02
topics: ["Libraries","Foundation"]
description: "Often when working with data from an API or third-party we'll need to manipulate or analyze it in a very specific way."
---

# #203: Simplifying Common String Operations with SwiftString 📝

By Jake Marsh, March 2, 2016. HTML: https://littlebitesofcocoa.com/203-simplifying-common-string-operations-with-swiftstring

Often when working with data from an **API** or third-party we'll need to manipulate or analyze it in a very specific way. In these cases, many of us simply search Google for "<i>how to do the thing to a String in Swift</i>". This usually works out fine, but what a bummer.

Today we'll check out a library from [Andrew Mayne](https://github.com/amayne) called [SwiftString](https://github.com/amayne/SwiftString), which can help us here.

[SwiftString](https://github.com/amayne/SwiftString) is essentially a collection of a <i>ton</i> of String manipulation and analysis utilities. It has **functions** like this:

``` swift
"<rock>blah</hardplace>".between("<rock>", "</hardplace>") // "blah"
```

``` swift
"hello".isNumeric() // false
"hello7".isNumeric() // false
"31.0".isNumeric() // true
"-31.0".isNumeric() // true
```

``` swift
"star wars".split(" ")[0] // "star"
```

``` swift
"star wars"[0...1] // "st"
```

``` swift
"#203: Simplifying Common String Operations".slugify() // "203-simplifying-common-string-operations"
```

``` swift
"Some [string], *with* %junk in it.)".stripPunctuation() // "Some string with junk in it"
```

``` swift
"yay &quot;strings&quot;".decodeHTML() // "yay \"strings\""
```

We might only need one or two of these functions in a single app, but thanks to [SwiftString](https://github.com/amayne/SwiftString), we'll never have to write them ourselves again.

More info about _SwiftString_ can be found at [git.io/swiftstring](http://git.io/swiftstring)
