SORU
28 EKİM 2011, Cuma


Nasıl bir NSString belirli başka bir dize ile başlar olmadığını görmek için?

Eğer URL olarak kullanacağım bir dize http ile başlar olmadığını görmek için kontrol etmek için çalışıyorum. Şu anda kontrol etmeye çalışıyorum düzgün görünmüyor. İşte benim kod:

NSMutableString *temp = [[NSMutableString alloc] initWithString:@"http://"];
if ([businessWebsite rangeOfString:@"http"].location == NSNotFound){
    NSString *temp2 = [[NSString alloc] init];
    temp2 = businessWebsite;
    [temp appendString:temp2];
    businessWebsite = temp2;
    NSLog(@"Updated BusinessWebsite is: %@", businessWebsite);
}

[web setBusinessWebsiteUrl:businessWebsite];

Herhangi bir fikir?

CEVAP
28 EKİM 2011, Cuma


Bu deneyin: if ([myString hasPrefix:@"http"]).

Bu arada, test != NSNotFound == NSNotFound yerine olmalıdır. Ama URL maç olacak ftp://my_http_host.com/thing, ama yapamazsın deme.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Dogbert files

    Dogbert file

    12 Ocak 2012
  • MVLV28

    MVLV28

    17 Mart 2008
  • Pepsi

    Pepsi

    1 Kasım 2005