0

i've started iOS developing 2 days ago so i simply know nothing.so i am creating a basic browser. i already managed to make so that if the url is "facebook.com" it changes to "http://facebook.com" but when typing "facebook" the app just crashes. i was not able to check if there is "." in the input. i tried

for(int i=0; i<[urlString length]; i++){
    if([urlString characterAtIndex: i] == "."){ // also tried == @"." and isEqual: "."
       break;
    }
    else {
       urlString = [[NSString alloc] initWithFormat: @"%.com", urlString"];
    }
}

this doesnot seem to work. any help?

Wain
  • 118,658
  • 15
  • 128
  • 151
  • what is your intention here you want to format the url then use NSUTF8StringEncoding to format the url – Smile Nov 11 '14 at 13:39
  • validate your WS through this code http://stackoverflow.com/questions/1471201/how-to-validate-an-url-on-the-iphone – Balu Nov 11 '14 at 13:49

2 Answers2

0

I assume this code doesn't even compile. You have one quote too many in the else block after urlString and you need to use %@ as a placeholder for a string. Just % is not enough.

You can read more about the usage of stringWithFormat here

Tim Bodeit
  • 9,673
  • 3
  • 27
  • 57
  • well that might be a problem but first problem to solve is that it cant check if there is decimal or not –  Nov 11 '14 at 13:50
0

Try this to find out if your string contains some char/substring

NSString *string = @"facebook";
if ([string rangeOfString:@"."].location == NSNotFound) {
    NSLog(@"string does not contain '.'");
} else {
    NSLog(@"string contains '.'");
}
Viktor Kucera
  • 6,177
  • 4
  • 32
  • 43