Browse Source

add string extension to extract a substring from a string

B. Petersen 5 years ago
parent
commit
c767d2a90c
1 changed files with 7 additions and 0 deletions
  1. 7 0
      deltachat-ios/Helper/Extensions.swift

+ 7 - 0
deltachat-ios/Helper/Extensions.swift

@@ -1,6 +1,13 @@
 import UIKit
 import UIKit
 
 
 extension String {
 extension String {
+
+    func substring(_ from: Int, _ to: Int) -> String {
+        let idx1 = index(startIndex, offsetBy: from)
+        let idx2 = index(startIndex, offsetBy: to)
+        return String(self[idx1..<idx2])
+    }
+
     func containsCharacters() -> Bool {
     func containsCharacters() -> Bool {
         return !trimmingCharacters(in: [" "]).isEmpty
         return !trimmingCharacters(in: [" "]).isEmpty
     }
     }