方法壹:最直接。
ns string * urlString = @ "/img/Baidu _ logo _ fqj _ 10 . gif ";
ns string * fileName =[urlString lastPathComponent];
NSLog(@“% @”,文件名);
方法二:按字符或時間串切分。
對象-C
ns string * link = @ "/img/Baidu _ logo _ fqj _ 10 . gif ";
ns string * filename =[[ns string alloc]init];
NSArray * separated array =[[NSArray alloc]init];
separated array =[link components separated bystring:@ "/];
filename =[separated array last object];
NSLog(@“% @”,separated array);
NSLog(@“% @”,文件名);
[文件名發布];
方法3:將鏈接視為路徑。
ns string * urlString = @ "/img/Baidu _ logo _ fqj _ 10 . gif ";
NSArray * urlCom =[[NSArray alloc]init with array:[URL path components]];
NSLog(@“% @”,[urlCom last object]);
【urlCom發布】;
方法四:NSRange。攔截二進制文件時非常方便。
ns string * urlString = @ "/img/Baidu _ logo _ fqj _ 10 . gif ";
NSString * fileName
ns range range =[urlString range of string:@ "/" options:NSBackwardsSearch];
if (range.location!= NSNotFound)
{
fileName =[urlString substringromindex:range . location+1];
if([[fileName lower casestring]hasSuffix:@”。gif"])
{
NSLog(@“% @”,文件名);
}
其他
{
}
}
其他
{
返回;
} & lt/pre & gt;& ltbr & gt
& ltbr & gt
& ltpre & gt& lt/pre & gt;
& ltdiv id = " live margins _ control " style = " position:absolute;z-index:9999 " >& ltimg src = " " alt = " " height = " 5 " width = " 77 " style = " position:absolute;左:-77px;top:-5px " >& lt/div & gt;
& ltdiv id = " live margins _ control " style = " position:absolute;z指數:9999;top:220 px;左:5px寬度:1px;高度:1px " >
& ltimg src = " " alt = " " height = " 5 " width = " 77 " style = " position:absolute;左:-77px;top:-5px " >& lt/div & gt;
& ltpre & gt& lt/pre & gt;
& ltdiv id = " live margins _ control " style = " position:absolute;z-index:9999 " >& ltimg src = " " alt = " " height = " 5 " width = " 77 " style = " position:absolute;左:-77px;top:-5px " >& ltimg src = " " alt = " " style = " position:absolute;左:0;top:-5px " >& ltimg id = " monitor-play-button " src = " " alt = " " style = " position:absolute;左:1px;top:0 " >& lt/div & gt;
& ltpre & gt& lt/pre & gt;
& ltdiv id = " live margins _ control " style = " position:absolute;z-index:9999 " >& ltimg src = " " alt = " " height = " 5 " width = " 77 " style = " position:absolute;左:-77px;top:-5px " >& ltimg src = " " alt = " " style = " position:absolute;左:0;top:-5px " >& ltimg id = " monitor-play-button " src = " " alt = " " style = " position:absolute;左:1px;top:0 " >& lt/div & gt;
& ltpre & gt& lt/pre & gt;
& ltdiv id = " live margins _ control " style = " position:absolute;z-index:9999 " >& ltimg src = " " alt = " " height = " 5 " width = " 77 " style = " position:absolute;左:-77px;top:-5px " >& ltimg src = " " alt = " " style = " position:absolute;左:0;top:-5px " >& ltimg id = " monitor-play-button " src = " " alt = " " style = " position:absolute;左:1px;top:0 " >& lt/div & gt;
& ltpre & gt& lt/pre & gt;
& ltdiv id = " live margins _ control " style = " position:absolute;z-index:9999 " >& ltimg src = " " alt = " " height = " 5 " width = " 77 " style = " position:absolute;左:-77px;top:-5px " >& ltimg src = " " alt = " " style = " position:absolute;左:0;top:-5px " >& ltimg id = " monitor-play-button " src = " " alt = " " style = " position:absolute;左:1px;top:0 " >& lt/div & gt;
& ltpre & gt& lt/pre & gt;
& ltdiv id = " live margins _ control " style = " position:absolute;z-index:9999 " >& ltimg src = " " alt = " " height = " 5 " width = " 77 " style = " position:absolute;左:-77px;top:-5px " >& ltimg src = " " alt = " " style = " position:absolute;左:0;top:-5px " >
& ltimg id = " monitor-play-button " src = " " alt = " " style = " position:absolute;左:1px;top:0 " >& lt/div & gt;
& ltpre & gt& lt/pre & gt;
& ltdiv id = " live margins _ control " style = " position:absolute;z-index:9999 " >& ltimg src = " " height = " 5 " width = " 77 " alt = " " style = " position:absolute;左:-77px;top:-5px " >
& ltimg src = " " alt = " " style = " position:absolute;左:0;top:-5px " >& ltimg id = " monitor-play-button " src = " " alt = " " style = " position:absolute;左:1px;top:0 " >& lt/div & gt;