You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

6 years ago
5 years ago
6 years ago
6 years ago
  1. //
  2. // StringExtension.swift
  3. // GMERemittance
  4. //
  5. // Created by Sujal on 12/13/17.
  6. // Copyright © 2017 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import Foundation
  9. extension String {
  10. var imageURLInResource: String {
  11. switch self {
  12. case "001": return "ic_cap"
  13. case "002": return "ic_tshirt"
  14. case "003": return "ic_glass"
  15. case "004": return "ic_watch"
  16. default:
  17. return ""
  18. }
  19. }
  20. var isBlank: Bool {
  21. get {
  22. return trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty
  23. }
  24. }
  25. func toBase64() -> String {
  26. let data = self.data(using: String.Encoding.utf8)
  27. return data!.base64EncodedString()
  28. }
  29. func removeWhitespacesInBetween() -> String {
  30. return components(separatedBy: .whitespaces).joined()
  31. }
  32. func stringRemovingComma() -> String {
  33. return components(separatedBy: ",").joined()
  34. }
  35. func getDateFromDateTime() -> String {
  36. return components(separatedBy: .whitespaces)[0]
  37. }
  38. func removeSpacesTrailingPreceding() -> String {
  39. return trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
  40. }
  41. func capitalizeFirstLetter() -> String {
  42. let first = String(characters.prefix(1)).capitalized
  43. let other = String(characters.dropFirst())
  44. return first + other
  45. }
  46. }