• 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: searching a Unicode string in a text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: searching a Unicode string in a text


  • Subject: Re: searching a Unicode string in a text
  • From: Ondra Cada <email@hidden>
  • Date: Fri, 20 Sep 2002 12:52:27 +0200

On Friday, September 20, 2002, at 11:36 , Arthur Clemens wrote:

The compiler can't read Unicode char escapes, and that's that. Search
archives, this was extensively discussed already.

Well, if you know the words with which to search its easier.

"Unicode"? I have extremely little experience myself: living in an obscure socialistic state, I can't afford a leased line, and don't online search much, lest my dialup went prohibitively expensive.

Also that's why I've continued:

If the string is one-char and fixed, the best solution would probably
be stringWithCharacters: and a unichar variable; otherwise, the best
way to go are localizable strings.

Ok thanks
so I can use

unichar unicharCode = 0x278A; // DINGBAT NEGATIVE CIRCLED
SANS-SERIF DIGIT ONE
NSString *unicharString = [NSString
stringWithCharacters:&unicharCode length:1];

NSRange range = [string rangeOfString:unicharString];

Yup. Should work right, does it?

if( range.location == 0 && range.length == [string length] ) return
[[[NSString alloc] initWithString:@"1"] autorelease];

I don't quite follow this part.

- if you just wanted to know whether the string is at the beginning ("range.location==0"), you can use hasPrefix: instead of rangeOfString:;
- if you just wanted to know whether the string was found anywhere, the appropriate test is "range.length>0" (or range.location!=NSNotFound; both work as well, I prefer the former myself);
- returning a string for a de-facto boolean looks strange, but still it might be a good design (I don't know your app). Nevertheless...
- *generally*, instead of the alloc/init/autorelease pattern you should use the appropriate convenience constructor, ie. "return [NSString stringWithString:...];"
- but in this particular case you should return just the static instance: "return @"1";"
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: searching a Unicode string in a text
      • From: Ondra Cada <email@hidden>
References: 
 >Re: searching a Unicode string in a text (From: Arthur Clemens <email@hidden>)

  • Prev by Date: NSTextStorage setAttributedString problems
  • Next by Date: Re: runModalForWindow allows window switching
  • Previous by thread: Re: searching a Unicode string in a text
  • Next by thread: Re: searching a Unicode string in a text
  • Index(es):
    • Date
    • Thread