{"id":2015,"url":"https://github.com/amayne/SwiftString","last_synced_at":"2025-08-02T05:33:31.124Z","repository":{"id":50515384,"uuid":"50782407","full_name":"amayne/SwiftString","owner":"amayne","description":"A comprehensive, lightweight string extension for Swift","archived":false,"fork":false,"pushed_at":"2017-03-23T08:41:23.000Z","size":942,"stargazers_count":1620,"open_issues_count":14,"forks_count":141,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-07-02T21:52:53.211Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amayne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-31T16:01:39.000Z","updated_at":"2025-06-22T05:51:21.000Z","dependencies_parsed_at":"2022-09-20T12:56:38.020Z","dependency_job_id":null,"html_url":"https://github.com/amayne/SwiftString","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/amayne/SwiftString","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amayne%2FSwiftString","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amayne%2FSwiftString/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amayne%2FSwiftString/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amayne%2FSwiftString/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amayne","download_url":"https://codeload.github.com/amayne/SwiftString/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amayne%2FSwiftString/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268339405,"owners_count":24234544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:01.295Z","updated_at":"2025-08-02T05:33:30.838Z","avatar_url":"https://github.com/amayne.png","language":"Swift","funding_links":[],"categories":["Swift","UI","Text","Libs"],"sub_categories":["Layout","Other free courses","Other Testing","Text","Keychain"],"readme":"# SwiftString\n\n[![CI Status](http://img.shields.io/travis/amayne/SwiftString.svg?style=flat)](https://travis-ci.org/amayne/SwiftString)\n[![Version](https://img.shields.io/cocoapods/v/SwiftString.svg?style=flat)](http://cocoapods.org/pods/SwiftString)\n[![License](https://img.shields.io/cocoapods/l/SwiftString.svg?style=flat)](http://cocoapods.org/pods/SwiftString)\n[![Platform](https://img.shields.io/cocoapods/p/SwiftString.svg?style=flat)](http://cocoapods.org/pods/SwiftString)\n[![Swift-2.1](http://img.shields.io/badge/Swift-2.1-blue.svg)]()\n\nSwiftString is a lightweight string extension for Swift.\nThis library was motivated by having to search StackOverflow for common string operations,\nand wanting them to be in one place with test coverage.\n\n## Installation\n\nSwiftString is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod \"SwiftString\"\n```\n\n## Usage\n\n```swift\nimport SwiftString\n```\n\n## Methods\n\n**between(left, right)**\n```swift\n\"\u003ca\u003efoo\u003c/a\u003e\".between(\"\u003ca\u003e\", \"\u003c/a\u003e\") // \"foo\"\n\"\u003ca\u003e\u003ca\u003efoo\u003c/a\u003e\u003c/a\u003e\".between(\"\u003ca\u003e\", \"\u003c/a\u003e\") // \"\u003ca\u003efoo\u003c/a\u003e\"\n\"\u003ca\u003efoo\".between(\"\u003ca\u003e\", \"\u003c/a\u003e\") // nil\n\"Some strings } are very {weird}, dont you think?\".between(\"{\", \"}\") // \"weird\"\n\"\u003ca\u003e\u003c/a\u003e\".between(\"\u003ca\u003e\", \"\u003c/a\u003e\") // nil\n \"\u003ca\u003efoo\u003c/a\u003e\".between(\"\u003ca\u003e\", \"\u003ca\u003e\") // nil\n```\n\n**camelize()**\n```swift\n\"os version\".camelize() // \"osVersion\"\n\"HelloWorld\".camelize() // \"helloWorld\"\n\"someword With Characters\".camelize() // \"somewordWithCharacters\"\n\"data_rate\".camelize() // \"dataRate\"\n\"background-color\".camelize() // \"backgroundColor\"\n```\n\n\n**capitalize()**\n```swift\n\"hello world\".capitalize() // \"Hello World\"\n```\n\n**chompLeft(string)**\n```swift\n\"foobar\".chompLeft(\"foo\") // \"bar\"\n\"foobar\".chompLeft(\"bar\") // \"foo\"\n```\n\n**chompRight(string)**\n```swift\n\"foobar\".chompRight(\"bar\") // \"foo\"\n\"foobar\".chompRight(\"foo\") // \"bar\"\n```\n\n**collapseWhitespace()**\n```swift\n\"  String   \\t libraries are   \\n\\n\\t fun\\n!  \".collapseWhitespace() // \"String libraries are fun !\")\n```\n\n**contains(substring)**\n```swift\n\"foobar\".contains(\"foo\") // true\n\"foobar\".contains(\"bar\") // true\n\"foobar\".contains(\"something\") // false\n```\n\n**count(string)**\n```swift\n\"hi hi ho hey hihey\".count(\"hi\") // 3\n```\n\n**decodeHTML()**\n```swift\n\"The Weekend \u0026#8216;King Of The Fall\u0026#8217;\".decodeHTML() // \"The Weekend ‘King Of The Fall’\"\n\"\u003cstrong\u003e 4 \u0026lt; 5 \u0026amp; 3 \u0026gt; 2 .\u003c/strong\u003e Price: 12 \u0026#x20ac;.  \u0026#64; \".decodeHTML() // \"\u003cstrong\u003e 4 \u003c 5 \u0026 3 \u003e 2 .\u003c/strong\u003e Price: 12 €.  @ \"\n\"this is so \u0026quot;good\u0026quot;\".decodeHTML() // \"this is so \\\"good\\\"\"\n```\n\n**endsWith(suffix)**\n```swift\n\"hello world\".endsWith(\"world\") // true\n\"hello world\".endsWith(\"foo\") // false\n```\n\n**ensureLeft(prefix)**\n```swift\n\"/subdir\".ensureLeft(\"/\") // \"/subdir\"\n\"subdir\".ensureLeft(\"/\") // \"/subdir\"\n```\n\n**ensureRight(suffix)**\n```swift\n\"subdir/\".ensureRight(\"/\") // \"subdir/\"\n\"subdir\".ensureRight(\"/\") // \"subdir/\"\n```\n\n**indexOf(substring)**\n```swift\n\"hello\".indexOf(\"hell\"), // 0\n\"hello\".indexOf(\"lo\"), // 3\n\"hello\".indexOf(\"world\") // nil\n```\n\n**initials()**\n```swift\n\"First\".initials(), // \"F\"\n\"First Last\".initials(), // \"FL\"\n\"First Middle1 Middle2 Middle3 Last\".initials() // \"FMMML\"\n```\n\n**initialsFirstAndLast()**\n```swift\n\"First Last\".initialsFirstAndLast(), // \"FL\"\n\"First Middle1 Middle2 Middle3 Last\".initialsFirstAndLast() // \"FL\"\n```\n\n**isAlpha()**\n```swift\n\"fdafaf3\".isAlpha() // false\n\"afaf\".isAlpha() // true\n\"dfdf--dfd\".isAlpha() // false\n```\n\n**isAlphaNumeric()**\n```swift\n\"afaf35353afaf\".isAlphaNumeric() // true\n\"FFFF99fff\".isAlphaNumeric() // true\n\"99\".isAlphaNumeric() // true\n\"afff\".isAlphaNumeric() // true\n\"-33\".isAlphaNumeric() // false\n\"aaff..\".isAlphaNumeric() // false\n```\n\n**isEmpty()**\n```swift\n\" \".isEmpty() // true\n\"\\t\\t\\t \".isEmpty() // true\n\"\\n\\n\".isEmpty() // true\n\"helo\".isEmpty() // false\n```\n\n**isNumeric()**\n```swift\n\"abc\".isNumeric() // false\n\"123a\".isNumeric() // false\n\"1\".isNumeric() // true\n\"22\".isNumeric() // true\n\"33.0\".isNumeric() // true\n\"-63.0\".isNumeric() // true\n```\n\n**join(sequence)**\n```swift\n\",\".join([1,2,3]) // \"1,2,3\"\n\",\".join([]) // \"\"\n\",\".join([\"a\",\"b\",\"c\"]) // \"a,b,c\"\n\"! \".join([\"hey\",\"who are you?\"]) // \"hey! who are you?\"\n```\n\n**latinize()**\n```swift\n\"šÜįéïöç\".latinize() // \"sUieioc\"\n\"crème brûlée\".latinize() // \"creme brulee\"\n```\n\n**lines()**\n```swift\n\"test\".lines() // [\"test\"]\n\"test\\nsentence\".lines() // [\"test\", \"sentence\"]\n\"test \\nsentence\".lines() // [\"test \", \"sentence\"]\n```\n\n**pad(n, string)**\n```swift\n\"hello\".pad(2) // \"  hello  \"\n\"hello\".pad(1, \"\\t\") // \"\\thello\\t\"\n```\n\n**padLeft(n, string)**\n```swift\n\"hello\".padLeft(10) // \"          hello\"\n\"what?\".padLeft(2, \"!\") // \"!!what?\"\n```\n\n**padRight(n, string)**\n```swift\n\"hello\".padRight(10) // \"hello          \"\n\"hello\".padRight(2, \"!\") // \"hello!!\"\n```\n\n**startsWith(prefix)**\n```swift\n\"hello world\".startsWith(\"hello\") // true\n\"hello world\".startsWith(\"foo\") // false\n```\n\n**split(separator)**\n```swift\n\"hello world\".split(\" \")[0] // \"hello\"\n\"hello world\".split(\" \")[1] // \"world\"\n\"helloworld\".split(\" \")[0] // \"helloworld\"\n```\n\n**times(n)**\n```swift\n\"hi\".times(3) // \"hihihi\"\n\" \".times(10) // \"          \"\n```\n\n**toBool()**\n```swift\n\"asdwads\".toBool() // nil\n\"true\".toBool() // true\n\"false\".toBool() // false\n```\n\n**toFloat()**\n```swift\n\"asdwads\".toFloat() // nil\n\"2.00\".toFloat() // 2.0\n\"2\".toFloat() // 2.0\n```\n\n**toInt()**\n```swift\n\"asdwads\".toInt() // nil\n\"2.00\".toInt() // 2\n\"2\".toInt() // 2\n```\n\n**toDate()**\n```swift\n\"asdwads\".toDate() // nil\n\"2014-06-03\".toDate() // NSDate\n```\n\n**toDateTime()**\n```swift\n\"asdwads\".toDateTime() // nil\n\"2014-06-03 13:15:01\".toDateTime() // NSDate\n```\n\n**toDouble()**\n```swift\n\"asdwads\".toDouble() // nil\n\"2.00\".toDouble() // 2.0\n\"2\".toDouble() // 2.0\n```\n\n**trimmedLeft()**\n```swift\n\"        How are you? \".trimmedLeft() // \"How are you? \"\n```\n\n**trimmedRight()**\n```swift\n\" How are you?   \".trimmedRight() // \" How are you?\"\n```\n\n**trimmed()**\n```swift\n\"    How are you?   \".trimmed() // \"How are you?\"\n```\n\n**slugify()**\n```swift\n\"Global Thermonuclear Warfare\".slugify() // \"global-thermonuclear-warfare\"\n\"Crème brûlée\".slugify() // \"creme-brulee\"\n```\n\n**stripPunctuation()**\n```swift\n\"My, st[ring] *full* of %punct)\".stripPunctuation() // \"My string full of punct\"\n```\n\n**substring(startIndex, length)**\n```swift\n\"hello world\".substring(0, length: 1) // \"h\"\n\"hello world\".substring(0, length: 11) // \"hello world\"\n```\n\n**[subscript]**\n```swift\n\"hello world\"[0...1] // \"he\"\n\"hello world\"[0..\u003c1] // \"h\"\n\"hello world\"[0] // \"h\"\n\"hello world\"[0...10] // \"hello world\"\n```\n\n## Author\n\nAndrew Mayne, andrew@redbricklab.com\n\n## License\n\nSwiftString is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famayne%2FSwiftString","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famayne%2FSwiftString","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famayne%2FSwiftString/lists"}