Reputation: 11
I am trying to compare two strings
1. String read from a .strings file using the api, String(contentsOf: localizableFilePath, encoding: .ascii).propertyListFromStringsFileFormat()
2. Strings to be written to the strings file
The string comparison fails when there are newlines in the strings, i,e
the string 1 has newLine character in them so its like
"something
something"
and string 2 is like "something \nsomething"
and the comparison fails because of this.
Upvotes: 0
Views: 278
Reputation: 150615
You can try replacing occurrences of newline characters with an empty string: For example:
let inputString = "Something \nSomething"
let test = "Something Something"
test == inputString.replacingOccurrences(of: "\n", with: "") // true
Upvotes: 1