{"id":26326211,"url":"https://github.com/kk-vv/substring","last_synced_at":"2025-10-11T21:39:41.921Z","repository":{"id":79748150,"uuid":"86872434","full_name":"kk-vv/Substring","owner":"kk-vv","description":"Swift3.x  Substring  String.Index","archived":false,"fork":false,"pushed_at":"2017-04-01T02:03:10.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-07T08:02:15.286Z","etag":null,"topics":["index","string","substring"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kk-vv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-01T01:15:33.000Z","updated_at":"2017-04-01T02:01:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"bf536ede-79cf-4635-bfda-b452190a155f","html_url":"https://github.com/kk-vv/Substring","commit_stats":null,"previous_names":["kk-vv/substring"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kk-vv/Substring","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kk-vv%2FSubstring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kk-vv%2FSubstring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kk-vv%2FSubstring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kk-vv%2FSubstring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kk-vv","download_url":"https://codeload.github.com/kk-vv/Substring/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kk-vv%2FSubstring/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008836,"owners_count":26084517,"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-10-11T02:00:06.511Z","response_time":55,"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":["index","string","substring"],"created_at":"2025-03-15T19:35:48.528Z","updated_at":"2025-10-11T21:39:41.916Z","avatar_url":"https://github.com/kk-vv.png","language":"Swift","readme":"### `Swift 3.x String \u003cString.Index\u003e`\n\n\u003e\nlet numbers = \"123456789\"\n\n- `[]`\n\n```\nlet _1 = numbers[numbers.startIndex] // '1' (Character)\n```\n\n- `startIndex/endIndex`\n\n\u003e\nendIndex 非‘9’的位置\n\n```\nlet _1 = numbers.substring(to: numbers.index(after: numbers.startIndex)) //\"1\" (String)\n```\n\n- `before/after/offset`\n\n```\nlet _9          = numbers.substring(from: numbers.index(before: numbers.endIndex)) // \"9\"\nlet _23456789   = numbers.substring(from: numbers.index(after: numbers.startIndex)) // \"23456789\"\nlet _12         = numbers.substring(to: numbers.index(numbers.startIndex, offsetBy: 2)) // \"12\"\n```\n\n- `range`\n\n```\nlet startIndex  = numbers.index(numbers.startIndex, offsetBy: 3)\nlet endIndex    = numbers.index(numbers.endIndex, offsetBy: -3)\nlet _456        = numbers.substring(with: startIndex..\u003cendIndex) // \"456\"\n```\n\n- `extension`\n\n```\nextension String {\n    func index(at: Int) -\u003e Index {\n        return self.index(startIndex, offsetBy: at)\n    }\n    \n    func substring(from: Int) -\u003e String {\n        let fromIndex = index(at: from)\n        return substring(from: fromIndex)\n    }\n    \n    func substring(to: Int) -\u003e String {\n        let toIndex = index(at: to)\n        return substring(to: toIndex)\n    }\n    \n    func substring(with r:Range\u003cInt\u003e) -\u003e String {\n        let startIndex  = index(at: r.lowerBound)\n        let endIndex    = index(at: r.upperBound)\n        return substring(with: startIndex..\u003cendIndex)\n    }\n}\n```\n\n\u003e\n\n```\nlet _1      = numbers.substring(to: 1) \t// \"1\"\nlet _789    = numbers.substring(from: 6)// \"789\"\nlet _456    = numbers.substring(with: 4..\u003c7)// \"456\"\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkk-vv%2Fsubstring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkk-vv%2Fsubstring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkk-vv%2Fsubstring/lists"}