string - Capitalise first letter of every sentence -
how capitalise first letter of every sentence in string? should use .capitalisedstring
?
you can enumerate string
per sentences using nsstringenumerationoptions.bysentences
. detect "sentence" if first character upper-cased.
so, may not perfect, can try this:
import foundation let text:string = "lorem ipsum dolor elit, sed aliqfuas. imfs enim ad veniam, quis nostrud consequat? duis aute irure dolor in pariatur." var result = "" text.uppercasestring.enumeratesubstringsinrange(text.startindex..<text.endindex, options: .bysentences) { (_, range, _, _) in // ^^^^^^^^^^^^^^^^ enumerate upper cased string var substring = text[range] // retrieve substring original string let first = substring.removeatindex(substring.startindex) result += string(first).uppercasestring + substring } // result -> "lorem ipsum dolor elit, sed aliqfuas. imfs enim ad veniam, quis nostrud consequat? duis aute irure dolor in pariatur."
Comments
Post a Comment