字符串的截取
NSString* index=@"/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip";
对路径截取的9种操作
NSLog(@"1=%@",[index lastPathComponent]);
NSLog(@"2=%@",[index stringByDeletingLastPathComponent]);
NSLog(@"3=%@",[index pathExtension]);
NSLog(@"4=%@",[index stringByDeletingPathExtension]);
NSLog(@"5=%@",[index stringByAbbreviatingWithTildeInPath]);
NSLog(@"6=%@",[index stringByExpandingTildeInPath]);
NSLog(@"7=%@",[index stringByStandardizingPath]);
NSLog(@"8=%@",[index stringByResolvingSymlinksInPath]);
NSLog(@"9=%@",[[index lastPathComponent] stringByDeletingPathExtension]);
对应结果
1=2013_50.zip
2=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books
3=zip
4=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50
5=~/Documents/DownLoad/books/2013_50.zip
6=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip
7=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip
8=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip
9=2013_50
网络字节顺序(也就是大端模式)
htonl() //32位无符号整型的主机字节顺序到网络字节顺序的转换(小端->>大端)
htons() //16位无符号短整型的主机字节顺序到网络字节顺序的转换 (小端->>大端)
ntohl() //32位无符号整型的网络字节顺序到主机字节顺序的转换 (大端->>小端)
ntohs() //16位无符号短整型的网络字节顺序到主机字节顺序的转换 (大端->>小端)
typedef unsigned int uint_32 ;
typedef unsigned short uint_16 ;
//16位
#define BSWAP_16(x) \
(uint_16)((((uint_16)(x) & 0x00ff) << 8) | \
(((uint_16)(x) & 0xff00) >> 8) \
)
//32位
#define BSWAP_32(x) \
(uint_32)((((uint_32)(x) & 0xff000000) >> 24) | \
(((uint_32)(x) & 0x00ff0000) >> 8) | \
(((uint_32)(x) & 0x0000ff00) << 8) | \
(((uint_32)(x) & 0x000000ff) << 24) \
)
//无符号整型16位
uint_16 bswap_16(uint_16 x)
{
return (((uint_16)(x) & 0x00ff) << 8) |
(((uint_16)(x) & 0xff00) >> 8) ;
}
//无符号整型32位
uint_32 bswap_32(uint_32 x)
{
return (((uint_32)(x) & 0xff000000) >> 24) |
(((uint_32)(x) & 0x00ff0000) >> 8) |
(((uint_32)(x) & 0x0000ff00) << 8) |
(((uint_32)(x) & 0x000000ff) << 24) ;
}