Tag: nsstring

将NSCFString转换为NSString

我正在从服务器获取字典 myDictionary = { "rank":"1", "color":"red", "position":"middle" } 现在我想在if条件下检查关键“位置”的值 我正在这样做 if ([[myDictionary valueForKey:@"position"] isEqualToString:@"middle"]) { //do Some stuff } else{ //do some other stuff } 但[myDictionary valueForKey:@"position"]数据types是_NSCFString ,所以它不会正确地比较值,如果循环,即使值正确,也不会进入。 我如何将它转换成NSString以便我可以比较它在条件? 我看到了这些问题 NSString实例将其类作为NSCFString报告 从NSCFString获取NSString xcode中的NSString或NSCFString? 从这些问题中我才知道, NSString实际上是一个不同types的string对象的容器类。 一般来说,一个NSString构造函数确实返回一个实际types为NSCFString的对象,这是一个围绕Core Foundation CFString struct的薄包装。 但他们没有帮助我..没有人实际告诉如何转换成NSString,所以请不要标记为重复。

获取AvCaptureVideoDataOutput可用的实际NSStringVideoCVPixelFormatTypes

我正试图find一个AVFoundation输出接受的格式: self.theOutput=[[AVCaptureVideoDataOutput alloc]init]; if ([self.theSession canAddOutput:self.theOutput]) [self.theSession addOutput:self.theOutput]; 然后,我在之后插入一个断点: po [self.theOutput availableVideoCVPixelFormatTypes] 我得到这个: (NSArray *) $5 = 0x2087ad00 <__NSArrayM 0x2087ad00>( 875704438, 875704422, 1111970369 ) 我如何获得这些格式types的string值? 谢谢

将NSString转换为date

我有两个string:date1 = 3-3-2011; 我想转换成2011年3月3日,并显示在标签。 NSString *myString = 3-3-2011; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"d-MM-YYYY"]; NSDate *yourDate = [dateFormatter dateFromString:myString]; //now format this date to whatever you need… [dateFormatter setDateFormat:@"d-MMM-YYYY"]; NSString *resultString = [dateFormatter stringFromDate:yourDate]; [dateFormatter release]; 但是你的date= 2010-12-25 18:30:00 +0000 resultstring = 2010年12月26日 我想要2010年3月3日 请帮忙! 谢谢。

NSString stringWithContentsOfURL已弃用。 我该怎么办?

我写了一些使用stringWithContentsOfURL代码,但事实certificate,它现在已经被弃用了。 你能帮我replace吗? 这是我的代码: NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]]; NSArray *listItems = [locationString componentsSeparatedByString:@","]; 另外,有人可以有一些示例代码来显示它是如何工作的? 什么编码是在(我的2行上面)完成的原始代码? 我想保持兼容性,所以我应该select什么编码? 错误是什么意思,它用于什么?

UILineBreakMode与NSLineBreakMode

我看到一些UIStringDrawing方法已经被更新为在iOS 6.0中使用NSLineBreakMode而不是UILineBreakMode: 例如 – (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakMode 我如何检查这个以确保我的iOS 5用户和下面的用户继续使用UILineBreakMode?

查找string中字符的索引

我有一个stringNSString *Original=@"88) 12-sep-2012"; 或Original=@"8) blablabla"; 我只想打印“)”之前的字符,所以如何find字符“)”的索引。 或者我怎么能这样做? 提前致谢。

按分隔符分割string

我真的找不到这个答案 我有XCode中称为myString的多行NSString,它是一个HTML代码。 我需要按行浏览string,例如: myString = @"<html>" "<body>" "<head><title>My Page</title>"; 我怎样才能访问每行的行数? 喜欢: LineOne = myString.Lines[0]; LineTwo = myString.Lines[1]; 我怎么能做到这样的XCode? 我需要像Delphi中的Memo组件…

在Objective-C中,如何打印出N个空格? (使用stringWithCharacters)

以下是试图打印出N个空格(在本例中为12个): NSLog(@"hello%@world", [NSString stringWithCharacters:" " length:12]); const unichar arrayChars[] = {' '}; NSLog(@"hello%@world", [NSString stringWithCharacters:arrayChars length:12]); const unichar oneChar = ' '; NSLog(@"hello%@world", [NSString stringWithCharacters:&oneChar length:12]); 但是他们都打印出怪异的东西,比如hello ÔÅÓñüÔÅ®Óñü®ÓüÅ®ÓñüÔ®ÓüÔÅ®world ,我认为“字符数组”和“string”是一样的,和“指向字符的指针”是一样的, ? API规范说,它是一个“Unicode字符的C数组”(通过Unicode,是UTF8吗?如果是,那么它应该与ASCII兼容)…如何使它工作,为什么这3种方式赢得不工作?

NSString中的后缀有序的后缀

NSString中有一种方式来输出st,nd和rd,但是以上标格式输出吗? 任何已知的unicode也许?

如何清除iOS中的特定域的cookie?

我已经search了StackOverflow的几乎所有问题,以回答我的问题。 我还没有find任何有用的链接或教程说哪种方式是最好的清除特定域的Cookie。 所以请如果有人能帮助我。