# Finding Character in CharacterSet

**URL:** <https://forums.swift.org/t/finding-character-in-characterset/11462>\
**Category:** Using Swift\
**Tags:** string\
**Created:** [March 29, 2018, 12:44am UTC](https://forums.swift.org/t/finding-character-in-characterset/11462 "2018-03-29T00:44:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![allevato](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/allevato/32/385_2.png) [@allevato](https://forums.swift.org/u/allevato)\
**Post date:** [March 29, 2018, 1:19am UTC](https://forums.swift.org/t/finding-character-in-characterset/11462/2 "2018-03-29T01:19:06Z")

</div>

I think `CharacterSet` is probably the wrong way to think about this problem, for the reasons you noted—it's actually a set of `Unicode.Scalar`s, so you can't properly handle multi-scalar grapheme clusters by using it.

It would also be a bit difficult to express something like "a set of `Character`s that are lowercase", especially if you wanted that to be an iterable collection, since that would include _many_ combinations of base letters followed by arbitrarily long sequences of combining modifiers. In fact, I believe such a set would be infinite, because you can stack modifiers ad infinitum (and thus, zalgo was born).

In this particular case, I think what you really want is predicates like `isLowercase` on `Character`, which would handle something like "ọ̀" correctly by implementing the test as defined by the Unicode Standard that handles the complete grapheme cluster instead of testing individual scalars. Then, you could just write `str.prefix(while: { $0.isLowercase })` and be done with it.

@Michael_Ilseman and I have been discussing scalar and character properties in [this thread](https://forums.swift.org/t/adding-unicode-properties-to-unicodescalar-character/9310), which may interest you.

---

_[View the full topic](https://forums.swift.org/t/finding-character-in-characterset/11462)._
