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

  • boburnham

    boburnham

    11 Temmuz 2006
  • Branboy3

    Branboy3

    12 AĞUSTOS 2012
  • Eric Enge

    Eric Enge

    2 Kasım 2009