{"id":15038097,"url":"https://github.com/balestrapatrick/stryng","last_synced_at":"2025-04-13T06:35:40.935Z","repository":{"id":62456164,"uuid":"112843382","full_name":"BalestraPatrick/Stryng","owner":"BalestraPatrick","description":"Swift strings taken to a whole new syntax level.","archived":false,"fork":false,"pushed_at":"2019-01-21T12:03:21.000Z","size":241,"stargazers_count":261,"open_issues_count":0,"forks_count":9,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-26T23:05:05.628Z","etag":null,"topics":["string","substring","swift","swift4"],"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/BalestraPatrick.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":"2017-12-02T13:15:45.000Z","updated_at":"2025-03-25T18:20:21.000Z","dependencies_parsed_at":"2022-11-02T00:17:21.034Z","dependency_job_id":null,"html_url":"https://github.com/BalestraPatrick/Stryng","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BalestraPatrick%2FStryng","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BalestraPatrick%2FStryng/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BalestraPatrick%2FStryng/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BalestraPatrick%2FStryng/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BalestraPatrick","download_url":"https://codeload.github.com/BalestraPatrick/Stryng/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675234,"owners_count":21143763,"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","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":["string","substring","swift","swift4"],"created_at":"2024-09-24T20:37:03.934Z","updated_at":"2025-04-13T06:35:40.911Z","avatar_url":"https://github.com/BalestraPatrick.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"header.png\"/\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://circleci.com/gh/BalestraPatrick/Stryng\"\u003e\n        \u003cimg src=\"https://circleci.com/gh/BalestraPatrick/Stryng/tree/master.svg?style=svg\" alt=\"Circle CI\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/Carthage/Carthage\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/carthage-compatible-4BC51D.svg?style=flat\" alt=\"Carthage\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://cocoapods.org/pods/Stryng\"\u003e\n        \u003cimg src=\"https://img.shields.io/cocoapods/l/Stryng.svg?style=flat\" alt=\"License\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://cocoapods.org/pods/Stryng\"\u003e\n        \u003cimg src=\"https://img.shields.io/cocoapods/p/Stryng.svg?style=flat\" alt=\"Platform\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://twitter.com/BalestraPatrick\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/contact-@BalestraPatrick-yellow.svg?style=flat\" alt=\"Twitter: @BalestraPatrick\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n# Stryng\n`Stryng` is designed to make it easier to work with strings by using the common and easy to remember subscript syntax and accessing characters and ranges with `Int` indices.\n\nSwift's strings management is one of the most painful feature of the language. Sure, it's great to have Unicode correctness and efficiency, but this comes at a cost: too much verbosity and complexity.\n\n## Examples\n\nRetrieve a single character at a specific position.\n\n```swift\nlet string = \"Example\"\n// With Stryng\nstring[1] // \"x\"\n// Without\nstring[string.index(string.startIndex, offsetBy: 1)] // \"x\"\n```\n\nRetrieve the substring up to a specific index.\n\n```swift\nlet string = \"Example\"\n// With Stryng\nstring[..\u003c2] // \"Ex\"\n// Without\nstring[..\u003cstring.index(string.startIndex, offsetBy: 2)] // \"Ex\"\n```\n\nRetrieve the substring between two indices.\n\n```swift\nlet string = \"Example\"\n// With Stryng\nstring[1..\u003c6] // \"xampl\"\n// Without\nstring[string.index(string.startIndex, offsetBy: 1)..\u003cstring.index(string.startIndex, offsetBy: 6)] // \"Ex\"\n```\n\nRetrieve positions of a all substring occurences.\n\n```swift\nlet string = \"Example Example\"\nlet occurences = string[\"xa\"] // Returns a [Range\u003cString.Index\u003e] containing all positions of the subtring.\n```\n\nConvert a `Substring` to a `String`.\n\n```swift\nlet example = \"Example\"\nexample[1...5].string // Returns a `String?` instead of a `Substring?`\n```\n\n## Usage\nThis is an up to date list of the supported subscripts. Take a look at [`StryngTests.swift`](https://github.com/BalestraPatrick/Stryng/blob/master/Tests/StryngTests/StryngTests.swift)  if you want to see some more real code examples.\n\n```swift\n// String[1]\npublic subscript(index: Int) -\u003e Character?\n\n// String[0..\u003c1]\npublic subscript(range: Range\u003cInt\u003e) -\u003e Substring?\n\n// String[0...1]\npublic subscript(range: ClosedRange\u003cInt\u003e) -\u003e Substring?\n\n// String[..\u003c1]\npublic subscript(value: PartialRangeUpTo\u003cInt\u003e) -\u003e Substring?\n\n// String[...1]\npublic subscript(value: PartialRangeThrough\u003cInt\u003e) -\u003e Substring?\n\n// String[1...]\npublic subscript(value: PartialRangeFrom\u003cInt\u003e) -\u003e Substring?\n\n// String[\"substring\"]\npublic subscript(string: String) -\u003e [Range\u003cString.Index\u003e]\n\n// String[\"begin\"...\"end\"]\npublic subscript(range: ClosedRange\u003cString\u003e) -\u003e [ClosedRange\u003cString.Index\u003e]\n\n// String[\"begin\"..\u003c\"end\"]\npublic subscript(range: Range\u003cString\u003e) -\u003e [Range\u003cString.Index\u003e]\n\n// String[Character(\"a\")]\npublic subscript(character: Character) -\u003e [String.Index]\n\n// String[\"begin\"...]\npublic subscript(range: PartialRangeFrom\u003cString\u003e) -\u003e PartialRangeFrom\u003cString.Index\u003e?\n\n// String[...\"end\"]\npublic subscript(range: PartialRangeThrough\u003cString\u003e) -\u003e PartialRangeThrough\u003cString.Index\u003e?\n```\n\n## Installation\n\n### Cocoapods\n\nTo install via [Cocoapods](http://cocoapods.org/), add the following line to your Podfile:\n\n```ruby\npod 'Stryng'\n```\n\n### Swift Package Manager\n\nTo install via the [Swift Package Manager](https://swift.org/package-manager/), add the following line to the `dependencies` array in your `Package.swift` file:\n\n```swift\n.package(url: \"https://github.com/BalestraPatrick/Stryng.git\", from: \"0.4.1\")\n```\n\nThen, still in your `Package.swift`, add `\"Stryng\"` to your *target's* `dependencies` array.\n\nFinally, in your terminal, run the following command to update your dependencies:\n\n```bash\n$ swift package update\n```\n\n## Disclosure\nYes, string traversal in Swift can be slow. The reason why these subscripts don't exist in the standard library is that some people think that it hides the performance implications of traversing a string. Traversing a string from the `startIndex` until the `endIndex` has complexity O(n). \nIf you need to get a character at a specific index, in one way or another you will have to traverse the string, but why would you need 3 lines of code instead of 1 to do that if you know what you're doing?\n\nThis is why Stryng is here to help you.\n\n## Contribute\nWe'd love your help. \nHead over to the [issues](https://github.com/BalestraPatrick/Stryng/issues) with your feedback. \nBonus points if you open a [Pull request](https://github.com/BalestraPatrick/Stryng/pulls) with a failing test for a bug or a new feature! ⭐️\n\n## Author\n\nI'm [Patrick Balestra](http://www.patrickbalestra.com).\n\nEmail: [me@patrickbalestra.com](mailto:me@patrickbalestra.com)\n\nTwitter: [@BalestraPatrick](http://twitter.com/BalestraPatrick).\n\n## License\n\n`Stryng` is available under the MIT license. See the [LICENSE](LICENSE) file for more info.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalestrapatrick%2Fstryng","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbalestrapatrick%2Fstryng","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalestrapatrick%2Fstryng/lists"}