A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 泥娃娃 中级黑马   /  2016-3-17 21:15  /  655 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. //1.判断字符串前缀
  2. //     [str   hasPrefix:@"要检测内容"]返回值是bool类型
  3. //        网址前缀http://   https://   file://     ftp://
  4.     NSString *str = @"http://ios,itcast.cn";
  5.         if ([str hasPrefix:@"http://"]||[str hasPrefix:@"https://"]||[str hasPrefix:@"file://"]||[str hasPrefix:@"ftp://"]) {
  6.             NSLog(@"是一个网址");
  7.         }else{
  8.             NSLog(@"不是一个网址");
  9.         }
  10. //2.判断字符串后缀
  11. // 格式:  [str hasSuffix:@"要检测的内容"];  返回值是bool类型
  12.         NSString *str2 = @"xxxx.ipg";
  13.         if ([str hasSuffix:@.jpg]) {
  14.             NSLog(@"是一张图片");
  15.         }else{
  16.             NSLog(@"不是一张图片");

  17.         }
复制代码

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马