//文字反轉 -(NSString *)stringByReversed:(NSString*)sourceString{ NSUInteger i = 0; NSUInteger j = sourceString.length - 1; unichar characters[sourceString.length]; while (i < j) { characters[j] = [sourceString characterAtIndex:i]; characters[i] = [sourceString characterAtIndex:j]; i ++; j --; } if(i == j) characters[i] = [sourceString characterAtIndex:i];
//從c array中,把字元一個一個寫出來 return [NSString stringWithCharacters:characters length:sourceString.length]; }
//利用文字反轉來取得網址中的檔案名稱 NSString* tempString = [self stringByReversed:strURL]; NSRange search = [tempString rangeOfString:@"/"]; NSLog(@"%i", search.location); NSString* fileName =[self stringByReversed:[tempString substringToIndex:search.location]]; NSLog(@"%@",fileName);
沒有留言:
張貼留言