话不多说,直接上代码:
写在NSString的category里的方法:
- (NSString *)displacementWithLength:(int)length {
NSString *string = @"";
unsigned char css[self.length];
memcpy(css, [self cStringUsingEncoding:NSUTF8StringEncoding], self.length);
for (int i = 0; i < sizeof(css); i++) {
NSLog(@"%c",css[i]+length);
string = [string stringByAppendingFormat:@"%c",css[i]+length];
}
return string;
}
length代表移动的位数