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

  • gsipek

    gsipek

    20 Temmuz 2007
  • KRQE

    KRQE

    6 AĞUSTOS 2007
  • PamtheBlamofficial

    PamtheBlamof

    31 Aralık 2010