• 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: How to parse a search string..
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to parse a search string..


  • Subject: Re: How to parse a search string..
  • From: Graham Cox <email@hidden>
  • Date: Mon, 13 Feb 2012 10:22:41 +1100

On 13/02/2012, at 9:02 AM, David Delmonte wrote:

> I have a search box, and need to parse out some special characters (' and \). The search bar text is sbar.text.. How do I interrupt the string before it is sent and remove (or warn) of these characters... ? Many thanks..
>
> I've tried this:
>
> if ([sbar.text isEqualToString:(@"'")] || [sbar.text isEqualToString:(@"\\")]) {
> 			NSLog(@"Found You");
> 			sbar.text = nil;
>
> (This works when the characters are first in the string..)
>
> and this:
>
> NSString *protectedString1 = sbar.text;
> NSString *protectedString2 = [protectedString1 stringByReplacingOccurrencesOfString:@"'" withString:@" "];
> sbar.text = protectedString2;
>
> But this loops :)



At some point presumably this string is an input to some search method. Why not just strip or modify the string there? Then it doesn't matter where the string comes from, the search method will do the right thing according to your needs.

If you really have to annoy the user by rejecting their input as they go, there are delegate methods on the field editor which would allow you to validate the text as they type - look up "field editor" in the guides.

--Graham



_______________________________________________

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


  • Follow-Ups:
    • Re: How to parse a search string..
      • From: Uli Kusterer <email@hidden>
References: 
 >How to parse a search string.. (From: David Delmonte <email@hidden>)

  • Prev by Date: Re: Make Custom Struct Key-Value Coding Compliant
  • Next by Date: Re: Playing Music in Objective C
  • Previous by thread: How to parse a search string..
  • Next by thread: Re: How to parse a search string..
  • Index(es):
    • Date
    • Thread