# Am I overcomplicating String.Index?

**URL:** <https://forums.swift.org/t/am-i-overcomplicating-string-index/58822>\
**Category:** Using Swift\
**Tags:** string\
**Created:** [July 10, 2022, 3:20pm UTC](https://forums.swift.org/t/am-i-overcomplicating-string-index/58822 "2022-07-10T15:20:54Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [July 12, 2022, 7:36pm UTC](https://forums.swift.org/t/am-i-overcomplicating-string-index/58822/20 "2022-07-12T19:36:29Z")

</div>

If you don't mind slow index operations (including accidentally quadratic algorithms in case you, say, go through each character of a string and do a subscript with integer index) then consider [this simple wrapper](https://forums.swift.org/t/how-to-write-my-own-extension-to-enable-python-like-string-indexing/58245/8). This might be ok for tests and short strings, just avoid using it in real apps in production.

> [@How to write my own extension to enable Python-like String indexing?](https://forums.swift.org/t/how-to-write-my-own-extension-to-enable-python-like-string-indexing/58245/8):
>
> ```swift
> let text = "hello"
> print(text[slow: 0..<2]) // "he"
> print(text[slow: 0...2]) // "hel"
> print(text[slow: 1...]) // "ello"
> print(text[slow: ..<2]) // "he"
> print(text[slow: ...2]) // "hel"
> 
> ```

---

_[View the full topic](https://forums.swift.org/t/am-i-overcomplicating-string-index/58822)._
