Objective c StringByTrimmingCharactersSet:消息不工作
这是令人恼火的,但我不能让这个代码工作,首先我认为这是一个可变/不可变的问题,但我相信它不是。 我做错了什么?labeledPemString do有内容,指定的字符集正在打印“范围开始{0,26}”。但未标记的BeginPenString与原始字符串相同Objective c StringByTrimmingCharactersSet:消息不工作,objective-c,iphone,nsstring,Objective C,Iphone,Nsstring,这是令人恼火的,但我不能让这个代码工作,首先我认为这是一个可变/不可变的问题,但我相信它不是。 我做错了什么?labeledPemString do有内容,指定的字符集正在打印“范围开始{0,26}”。但未标记的BeginPenString与原始字符串相同 //Get the .pem file contents NSString *path = [[NSBundle mainBundle] pathForResource:@"publickey" ofType:@"pem"]; NSMut
//Get the .pem file contents
NSString *path = [[NSBundle mainBundle] pathForResource:@"publickey" ofType:@"pem"];
NSMutableString *labeledPemString = [[NSMutableString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSLog(@"labeled %@", labeledPemString);
//Take off -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----- headers
//First get begin range
NSRange beginHeaderRange = [labeledPemString rangeOfString:@"-----BEGIN PUBLIC KEY-----"];
NSLog(@"ranges begin %@ ", NSStringFromRange(beginHeaderRange));
//Create a characterset with begin range
NSCharacterSet *beginHeaderChSet = [NSCharacterSet characterSetWithRange:beginHeaderRange];
//Trim text
NSMutableString *unlabeledBeginPemString = [[labeledPemString stringByTrimmingCharactersInSet:beginHeaderChSet] mutableCopy];
NSLog(@"unlabeled 1 %@", unlabeledBeginPemString);
感谢您的帮助。stringByTrimmingCharactersInSet:从接收器中删除集合中出现的字符。i、 e.如果
NSCharacterSet
包含a
和c
,并且
[@"abc" stringByTrimmingCharactersInSet:characterSet];
您将获得@“b”
,而characterSetWithRange:
中的范围是要放入字符集中的unicode的范围
我想这不是你想要的。如果只想从给定字符串中删除子字符串,只需使用