Questions tagged [unicodescalar]

4 questions
20
votes
3 answers

Swift convert 'Character' to 'Unicode.Scalar'

I'm trying to filter non-alphabetical characters out of a String, but running into the issue that CharacterSet uses Unicode.Scalar and String consists of Character. Xcode gives the error: Cannot convert value of type 'String.Element' (aka…
Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179
1
vote
2 answers

Count how many times a special character (non-spacing mark) occurs in a string in Swift

This function searches how many times a character appears in a string: let str = "الصَّبَاْحُ جَمِيْلٌ" let char: Character = "َ" func SpecificLetterCount(_ str:String, _ char:Character) -> Int { let letters = Array(str); var count = 0 for letter…
iaa
  • 49
  • 6
0
votes
2 answers

Deferent result in Unicode to String in Swift

I am translating my String value to unicodeScalars with this down code, for example if I gave "A" as input I will get 65 as output, now that I know 65 is number of A, then I want give 65 to receive A again, but it gave e, I am sure I am mixing some…
ios coder
  • 1
  • 4
  • 31
  • 91
0
votes
1 answer

Get unicodeScalars Character from String in a specific index in Swift

I'm using this extension that gets the character in a specific index; However currently it doesn't recognize unicodeScalars, can you help me fix the extension to get the results that I need? I've put some tests at the end that shows the result I…
iaa
  • 49
  • 6