Solved the Issue of substring not matching

In my project, I find a wired problem, we added More to an attribute string on swift, and set the different attribute for the last word More, but some times the word selected is not the More, but one letter less.

After debug the program, and find that it was caused by the string has html tag p on the string, and we removed part of the string in the end, and added More to the string, and add the string to NSAttributeString, and I find that the string with <p> in the beginning will add an \n to the end of the string.

I used the NSAttributeString.string method to get the pure string, and find that the end has \n.

Solution

The solution that I find is get the pure string before update data, so the html tag will be removed, and the string is correct right now.

Leave a Reply

Your email address will not be published. Required fields are marked *