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

  • infiniTuts

    infiniTuts

    18 Ocak 2012
  • Pituvision

    Pituvision

    11 Mart 2006
  • SunsetTrance

    SunsetTrance

    20 EYLÜL 2008