• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting a substring
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting a substring


  • Subject: Re: Getting a substring
  • From: Peter N Lewis <email@hidden>
  • Date: Sat, 6 Dec 2008 15:09:16 +0900

At 20:03 -0200 5/12/08, Ariel Rodriguez wrote:
My question is simple, at least that is what i think :)
I need to extract something like this: 01816560 from something like this: http://www.xxxx.com/diario/2008/12/05/um/m-01816560.htm My first idea was to use - (NSArray *)componentsSeparatedByString:(NSString *)separator with - first (to get the 01816560.htm and then - (NSArray *)componentsSeparatedByString:(NSString *)separator again with '.' But i am quite sure it should be a better way to do just that. Any idea?

It entirely depends on how the URL can change.

If the URL is always the same format, then you could just use substringWithRange with an appropriate range.

If the URL can change somewhat, and it is just the last component, then you could use lastPathComponent to get the last piece, and stringByDeletingPathExtension to remove the extension.

After that, how you get rid of the m- depends on how that part changes.

Ultimately, you could use a regex library, but while I find that indispensable, its probably overkill for this task.

Enjoy,
   Peter.

--
              Keyboard Maestro 3 Now Available!
                Now With Status Menu triggers!

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/>           <http://download.stairways.com/>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Getting a substring (From: Ariel Rodriguez <email@hidden>)

  • Prev by Date: Changing key behaviors for NSTableView
  • Next by Date: Re: D.O. [NSPortCoder sendBeforeTime:sendReplyPort:] timed out
  • Previous by thread: Re: Getting a substring
  • Next by thread: Child Window issues
  • Index(es):
    • Date
    • Thread