title: Trouble converting Substrings to Partial Range Operators Swift 4
body: <p>Having no luck creating a partial range in Swift 4</p>
  
  <pre><code>import Foundation
  
  public extension String {
  
  public var URLScheme: String? {
      guard let schemeRange = self.range(of: "://") else { return nil }
      return self.substring(to: schemeRange.lowerBound)
  }
  
  public var URLPortNumber: Int {
      guard let portRange = self.range(of: ":", options: .backwards) else { return -1 }
  
      let startIndex = self.index(portRange.upperBound, offsetBy: 0)
      let endIndex = self.index(portRange.upperBound, offsetBy: 2)
      guard self[startIndex...endIndex] != "//" else { return -1 }
  
      return Int(self.substring(from: portRange.upperBound))!
  }
  
  public var URLHost: String {
      var host = self
  
      if let scheme = self.URLScheme {
          host = host.substring(from: self.index(self.startIndex, offsetBy: (scheme + "://").characters.count))
      }
  
      if let portRange = host.range(of: ":") {
          host = host.substring(to: portRange.lowerBound)
      }
  
      return host
  
      }
  }
  </code></pre>
  
  <p>Also after reading the <a href="https://developer.apple.com/documentation/swift/substring" rel="nofollow noreferrer">documentation</a> on Substrings, I am still less than clear on their benefit. Has anyone used them for URLs?</p>
  
  <p>Even the syntax is less succinct than dot notation.</p>