title: Remove last portion of the NSURL: iOS
body: <p>I am trying to remove just the last part of the url, Its a FTP URL. </p>
  
  <p>Suppose, I have a URL like: > <a href="ftp://ftp.abc.com/public_html/somefolder/" rel="noreferrer">ftp://ftp.abc.com/public_html/somefolder/</a>. After removing the last portion I should have it as: <a href="ftp://ftp.abc.com/public_html/" rel="noreferrer">ftp://ftp.abc.com/public_html/</a>. </p>
  
  <p>I have tried using <code>stringByDeletingLastPathComponenet</code> and <code>URLByDeletingLastPathComponent</code>, but they dont remove the last portion correctly. They change the entire looks of the url. </p>
  
  <p>for instance, after using the above said methods, here is the URL format i get ftp:/ftp.abc.com/public_html/. It removes one "/" in "ftp://", which is crashing my program. </p>
  
  <p>How is it possible to removve just the last part without disturbing the rest of the URL ?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <pre><code>NSURL * stringUrl = [NSURL URLWithString:string];
  NSURL * urlByRemovingLastComponent = [stringUrl URLByDeletingLastPathComponent];
  NSLog(@"%@", urlByRemovingLastComponent);
  </code></pre>
  
  <p>Using above code, I get the output as :- ftp:/ftp.abc.com/public_html/</p>