Browse Source

add string extension to extract a substring from a string

B. Petersen 5 năm trước cách đây
mục cha
commit
c767d2a90c
1 tập tin đã thay đổi với 7 bổ sung0 xóa
  1. 7 0
      deltachat-ios/Helper/Extensions.swift

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

@@ -1,6 +1,13 @@
 import UIKit
 
 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 {
         return !trimmingCharacters(in: [" "]).isEmpty
     }