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

  • boogie2988

    boogie2988

    6 NİSAN 2006
  • Dellbear816

    Dellbear816

    4 Mart 2008
  • TheRightTire

    TheRightTire

    14 EKİM 2009