NSString要NSDate转换的回报null.
原始字符串输出" 2013-07-16T18:42:56 + 02:00 ",但当我尝试转换为NSDate它时返回"null"
这是我的代码:
// original string
NSString *str = [timeStamp objectAtIndex:indexPath.row];
// convert to date
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
//[dateFormat setDateFormat:@"YYYY-MM-dd'T'HH:mm:ss'+11:00'"];
[dateFormat setDateFormat:@"YYYY-MM-dd'T'HH:mm:ssZZZ"]; // updated from Stavash's post below. Still null is outputted for the date though
[dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"Australia/Melbourne"]];
NSDate *dte = [dateFormat dateFromString:str];
cell.timeStampLabel.text = [NSString stringWithFormat:@"%@",dte ];
Run Code Online (Sandbox Code Playgroud) 为什么我在以下位置将无法识别的选择器发送到实例
doesExist = [myStr isEqualToString:@"Hello"];
- (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"%s", __PRETTY_FUNCTION__);
NSLog(@"Found %d peripheral as a result of scanning", myListOfPeripherals.count);
NSString *strMACId = [advertisementData valueForKey:@"kCBAdvDataManufacturerData"];
NSLog(@"%@", strMACId);
[timerConnectionTimeout invalidate];
PeripheralCell * objPeripheralCell;
NSLog(@"Found Peripheral with Name: %@ RSSI data:%@ AdvData: %@", peripheral.name, peripheral.RSSI, advertisementData);
// Check if the Peripheral already exists in your collection - if no add it.
if ([self peripheralExistsWithMacId:strMACId] == false)
{
// New peripheral - Add it to the …Run Code Online (Sandbox Code Playgroud) 从Web服务,我得到一个JSON响应,看起来像这样.
{
data = {
category = "Barclays Premier Leaguejk";
"download_counter" = 1;
id = 2;
rating = 5;
tags = (
"Primera A",
"Primeira Liga"
);
title = "Carles Puyol";
};
status = 1;
}
Run Code Online (Sandbox Code Playgroud)
使用[data valueForKeyPath:@"tags"],我取出了子数组.
(
"Primera A",
"Primeira Liga"
)
Run Code Online (Sandbox Code Playgroud)
我需要把里面的值变成一个NSString.有一个简单的方法吗?
NSString *str = nil;
NSLog(@"str = %@",str);
NSLog(@"str.length = %u",str.length);
NSString *str2 = [NSString stringWithFormat:@"%@",str];
NSLog(@"str2 = %@",str2);
NSLog(@"str2.length = %u",str2.length);
Run Code Online (Sandbox Code Playgroud)
NSLog模式是:
str = (null)
str.length = 0
str2 = (null)
str2.length = 6
Run Code Online (Sandbox Code Playgroud)
str2.length = 6让我困惑,为什么?
我有一个NSArray持有一个或多个字符串.如果有多个,我想循环遍历数组并连接字符串以组合所有值.
我的决赛NSString应该是这样的@"food|cafe|restaurant".我该如何实现这一目标?
我正在更改一些预先编写的代码,视频时间标签的格式如下:
return [NSString stringWithFormat:@"%2d:%0.2d", minutes, seconds];
Run Code Online (Sandbox Code Playgroud)
发生的情况是,如果minutes是单个数字,它会在它之前返回一个空格,例如4:494 之前有一个空格。如果参数是 2 位数字minutes,但只有 1 个字符,如何格式化以使字符串中有 2 个字符如果minutes是1位数字?
NSString *expectedURL = [NSString stringWithFormat:@"https://%@:%ld/%@"];
什么做%@和%ld什么意思呢?
如何检测NSString已经编码的内容.
我正在编码我的字符串,如下所示.在编码之前我只想验证天气[product url]是否已编码.
NSString *encodedUrlString=[[product url] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Run Code Online (Sandbox Code Playgroud) 我厌倦了链接,但那些在我的情况下不起作用.
任何人都可以建议我如何将此字符串转换为json或字典.
这个字符串有一个包含字符串数组的字典.
NSString *temp=@"{\n name = {\n dob = \"\";\n age = \"61\";\n family = (\n {\n location = location;\n mobile = mobile;\n }\n );\n };\n}";
Run Code Online (Sandbox Code Playgroud)
这里的家庭是阵列.
我正在比较两个字符串.
问题是当我的两个字符串都是nil.我不知道两个字符串何时出现,nil然后为什么控制进入success阻止.
我正在使用此代码来比较字符串:
if(![oldString isEqualToString:newString])
{
//in case both are nil control reaches here
needToShowPopup = YES;
break;
}
Run Code Online (Sandbox Code Playgroud)
编辑:我想如果只有两个字符串不同,那么只有我的控件才能进入if statement.我的情况都失败了nil
nsstring ×10
objective-c ×9
ios ×5
cocoa ×2
cocoa-touch ×2
json ×2
encoding ×1
nsarray ×1
nsdate ×1
nsdictionary ×1
null ×1
string ×1