您好我正在尝试生成这种NSString
模式,我的真实string
是“abcdefgh
”我想通过使用
NSData *data=[mystring dataUsingEncoding:NSUTF8StringEncoding]
NSLog(@"%d",[data bytes]);
将这些值复制到byte array
中,并将总数组大小限制为24bit
。
然后我想创建以下模式
"abcdefgh efghabcd hgfedcba"
如何生成这种密钥?
请帮帮我
答案 0 :(得分:0)
我认为这会奏效。 reverseString的逻辑取自this answer
#import "NSString+CustomCrypto.h"
@implementation NSString (CustomCrypto)
- (NSString *)reversedString{
NSMutableString *reversedString = [NSMutableString stringWithCapacity:[self length]];
[self enumerateSubstringsInRange:NSMakeRange(0,[self length])
options:(NSStringEnumerationReverse | NSStringEnumerationByComposedCharacterSequences)
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
[reversedString appendString:substring];
}];
return [NSString stringWithString:reversedString];
}
- (NSString *)splicedString{
NSInteger index = [self length]/2;
NSString *subString = [self substringFromIndex:index];
NSString *secondString = [self substringToIndex:index];
return [subString stringByAppendingString:secondString];
}
- (NSString *)customCryptoString{
NSString *splicedString = [self splicedString];
NSString *reversedString = [self reversedString];
return [NSString stringWithFormat:@"%@ %@ %@",self, splicedString, reversedString];
}
调用字符串
的类别方法NSLog(@"%@",[@"abcdefgh" customCryptoString]);
输出:abcdefgh efghabcd hgfedcba