Swiftは文字列のスペースを削除します



Swift Removes Spaces Strings



文字列内のスペースをフィルタリングする

extension String { /* * Remove the leading and trailing spaces */ var removeHeadAndTailSpace:String { let whitespace = NSCharacterSet.whitespaces return self.trimmingCharacters(in: whitespace) } /* *Remove the leading and trailing spaces including the following newline */ var removeHeadAndTailSpacePro:String { let whitespace = NSCharacterSet.whitespacesAndNewlines return self.trimmingCharacters(in: whitespace) } /* * Remove all spaces */ var removeAllSapce: String { return self.replacingOccurrences(of: ' ', with: '', options: .literal, range: nil) } /* * Remove the leading and trailing spaces, specify the number of leading spaces */ func beginSpaceNum(num: Int) -> String { var beginSpace = '' for _ in 0..