Questions tagged [swift-string]

swift-string - use this tag only for questions about String type futures or problems in swift open-source programming language developed by Apple Inc.

25 questions
6
votes
2 answers

How could I get Apple emoji name instead of Unicode name?

I see that the Unicode name of an emoji and its Apple name as displayed in Character Viewer are different. How could I get an emoji's Apple name using Swift? Example: Emoji: Unicode Name (got via .applyingTransform(.toUnicodeName, reverse: false)):…
goldwalk
  • 341
  • 1
  • 2
  • 11
2
votes
1 answer

Why is unicode included as an Encoding in Swift's String API?

I read this very important blog regarding string encodings. After reading it I realized that unicode is a standard of mapping characters to code points which are integers. How these integers are stored in memory is an entirely different concept.…
Rohan Bhale
  • 1,323
  • 1
  • 11
  • 29
2
votes
1 answer

swift escaping backslash doesn't work as expected

When I print this: print("dfi:.*\\{8766370\\}.*:6582.*") the result on the log looks as expected: >>>> dfi:.*\{8766370\}.*:6582.* but when i construct the string dynamically the result looks wrong let re = "dfi:.*" + "\\" + "{" + "\(section)" +…
Avba
  • 14,822
  • 20
  • 92
  • 192
1
vote
1 answer

Is it possible to change Swift String Interpolation for the String typealias?

I have a lot of DTOs in my app which log some field. That field should not be logged because the data is kind of sensitive. The model looks like this: typealias HiddenFieldType = String struct DTO1 { var field1_1: String var fieldToHide:…
olha
  • 2,132
  • 1
  • 18
  • 39
1
vote
2 answers

swift string diacriticInsensitive not working correct

I am doing diacritic conversion on string. In Swedish it converts the letters åäö to aao. but iphone keyboard has åäö these letters. I couldn't understand why it converted these 3 letters. Is there an error in my code? Shouldn't the letters on the…
ursan526
  • 485
  • 3
  • 10
1
vote
1 answer

Limit text to a certain number of words in Swift

In a mobile App I use an API that can only handle about 300 words. How can I trimm a string in Swift so that it doesn't contain more words? The native .trimmingCharacters(in: CharacterSet) does not seem to be able to do this as it is intended to…
1
vote
1 answer

Why is using isEmpty preferable over a comparison with an empty string literal is Swift?

The String type is Swift has a property named isEmpty that indicates whether a string has no characters. I'd like to know if there's any difference between using isEmpty and checking the equality to an empty string literal. In other words, is…
Vadim Belyaev
  • 2,456
  • 2
  • 18
  • 23
1
vote
1 answer

What is String.Encoding.unicode?

Swift offers a series of encodings for strings. As of the time I'm writing this, none of them are documented, which makes this absurdly more confusing than it should be... I can understand that .ascii means it's ASCII encoded, .utf8 means the string…
Ky -
  • 30,724
  • 51
  • 192
  • 308
0
votes
1 answer

Swift 5.7 - The compiler cannot type-check complex regex which contains 5 captures

I wrote this code: let regex = Regex { let newline = #/\r|\n|\r\n/# let doubleNewline = Repeat(newline, count: 2) let dateFormatter = DateFormatter() "# Title" newline Capture {…
Nil
  • 11
  • 4
0
votes
2 answers

How to convert swift-struct object name using swift-string

I have a struct name called Car. Car has two attributes(noOfTyres, ownerName). struct Car { var noOfTyres: Int var ownerName: String } The string value is let objStr = "Car/ownerName" how to convert the objStr to swiftObject like…
S Surya
  • 87
  • 1
  • 1
  • 8
0
votes
2 answers

Convert Path String to Object Path in Swift

struct Student{ var rollNum : Int var name : String var contact : Contact } struct Contact{ var phoneNum : String var mailId : String } let contact = Contact(phoneNum : "1234567890", mailId : "abcd@xyz.com") let student =…
Lakshmi C
  • 31
  • 8
0
votes
1 answer

find non-alphabet words in any language with swift

I have multiple strings for some languages(english, italian, arabic, french ...etc). I want to see a list of words other than that language's alphabet. For example for English: "thisŞĞstring" -> return false "corect string format" -> return true For…
ursan526
  • 485
  • 3
  • 10
0
votes
0 answers

Replace character in a long dictionary with swift

I want to replace some characters in a dictionarys keys. There are about a hundred thousand keys in the dictionary. With the code below, this takes about an hour. Can we shorten this time by making changes in the coding? for…
ursan526
  • 485
  • 3
  • 10
0
votes
1 answer

String Format Specifiers : rounding rule used for decimal values

I am using String(format:) to convert a Float. I thought the number would be rounded. Sometimes it is. String(format: "%.02f", 1.455) //"1.46" Sometimes not. String(format: "%.02f", 1.555) //"1.55" String(round(1.555 * 100) / 100.0)…
Adrien
  • 1,579
  • 6
  • 25
0
votes
2 answers

Shift string Circular left and right in swift

On Hackerrank I came across this problem. I have a function that takes in 3 arguments. Example --> func getShiftedString(s: String, leftShifts: Int, rightShifts: Int) -> String Left Shift: A single circular rotation of the string in which the first…
1
2