String convert to Int and replace comma to Plus sign
问题 Using Swift, I'm trying to take a list of numbers input in a text view in an app and create a sum of this list by extracting each number for a grade calculator. Also the amount of values put in by the user changes each time. An example is shown below: String of: 98,99,97,96... Trying to get: 98+99+97+96... Please Help! Thanks 回答1: Use components(separatedBy:) to break up the comma-separated string. Use trimmingCharacters(in:) to remove spaces before and after each element Use Int() to convert