25 lines
669 B
Swift
25 lines
669 B
Swift
//
|
|
// File.swift
|
|
//
|
|
//
|
|
// Created by Juraldinio on 01.08.2022.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public extension String {
|
|
|
|
func trimCompact() -> String {
|
|
let value = self
|
|
.replacingOccurrences(of: "\n", with: "")
|
|
.replacingOccurrences(of: "\r", with: "")
|
|
|
|
let regex = try! NSRegularExpression(pattern: "[ ]{2,}", options: .caseInsensitive)
|
|
return regex.stringByReplacingMatches(in: value,
|
|
options: [],
|
|
range: NSRange(0..<value.utf16.count),
|
|
withTemplate: " ")
|
|
}
|
|
|
|
}
|