标签: nsstring

NSString没有正确显示

我有以下NSString:

NSString* searchURL = [NSString stringWithFormat:@"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22%@%22)%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=",symbol];  
    NSLog(@"URL IS: %@", searchURL);
Run Code Online (Sandbox Code Playgroud)

看起来%22在打印时不包括在内:

URL IS: http://query.yahooapis.com/v1/public/yql?q=select220from2ahoo.finance.quotes2here              `º?ymbol              813020n22@20X1.000982B6P-1042009&format=json&env=http0X1.8CFB8P-1023-1.9907460.000000datatables.org-1.990746alltables.env&callback=
Run Code Online (Sandbox Code Playgroud)

如何确保%22包含在我的字符串中?

iphone cocoa cocoa-touch objective-c nsstring

2
推荐指数
1
解决办法
206
查看次数

在Objective-C中操作字符串

我有一个10个字符的NSString.我需要添加一个破折号 - 在角色位置4和8.最有效的方法是什么?谢谢

iphone cocoa-touch objective-c nsstring

2
推荐指数
2
解决办法
1083
查看次数

NSString问题

我有一个NSString被赋予一个字符串值.如何在文件名和扩展名之间NSString插入并插入@"-thumbnail"

换句话说,我该怎么做:

NSString *fileName = @"myFile.png";
Run Code Online (Sandbox Code Playgroud)

至:

NSString *thumbnailName = [NSString someMagicFunction...]
NSLog(@"%@", thumbnailName);  // Should Output "myFile-thumbnail.png"
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch nsstring

2
推荐指数
1
解决办法
1755
查看次数

指针与nil初始化指针

只是想更好地理解ObjectiveC.

这两个表达式不应该相同吗?

NSString *str; //address of str is 0x438a5625
NSString *str=nil; //address of str is 0x0
Run Code Online (Sandbox Code Playgroud)

这种行为的原因是什么?

iphone pointers objective-c nsstring

2
推荐指数
1
解决办法
529
查看次数

以objective-c字符串格式添加零

快速问题:我试图用NSString stringWithFormat格式化字符串填充具有特定数量的零的空格.
例如,我想:

@"The number is %d", 5   // I want this to output 'the number is 05'
@"the number is %d", 10  // I want this to output 'the number is 10'
Run Code Online (Sandbox Code Playgroud)

我知道如何用Java做到这一点,但我似乎无法在objective-c中找到相同的功能.

任何帮助都会很棒.

iphone formatting numbers objective-c nsstring

2
推荐指数
1
解决办法
1344
查看次数

为什么需要保留NSString变量?

我的.h文件中有以下代码:

@interface Utils : NSObject {
    NSString *dPath;
}    
@property(nonatomic, retain) NSString *dPath;
Run Code Online (Sandbox Code Playgroud)

在我的.m文件中:

    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
dPath = [[documentPaths objectAtIndex:0] stringByAppendingPathComponent:kDatabaseName];
[dPath retain]; 
Run Code Online (Sandbox Code Playgroud)

如果dPath已经定义为(非原子,保留),为什么还要保留 dPath?如果我不添加[dPath retain]; 我得到一些奇怪的,随机的错误,并且在其他函数中使用此变量时应用程序崩溃.我想这是因为某些自动释放,但我没有.

那么,什么是(非原子的,保留)做什么呢?是否真的有必要[dPath保留]; 或者我只是隐藏其他东西?

iphone objective-c autorelease nsstring retain

2
推荐指数
1
解决办法
351
查看次数

评估/比较NSString和通配符?

嗨,我正在尝试评估一个NSString,看它是否符合某个标准,其中包含一个或多个星号字符形式的通配符.

例:

NSString *filePath = @"file://Users/test/Desktop/file.txt";
NSString *matchCriteria = @"file://*/file.*";
Run Code Online (Sandbox Code Playgroud)

我想看看是否filePath匹配(适合?)matchCriteria,在这个例子中它确实如此.有谁知道我该怎么做呢?

非常感谢!

iphone wildcard objective-c nsstring

2
推荐指数
1
解决办法
2799
查看次数

如何在两个单词之间获得NSString?

我有以下格式的NSString

NSString *string1 = @"webservices/employee/1"; 和另一个字符串
NSString *string2 = @"webservices/manaager/1";

我想使用常用方法在"werbservice /"和"/ 1"之间获取字符串.

有没有办法做到这一点?

iphone objective-c nsstring

2
推荐指数
1
解决办法
1531
查看次数

Objective-C - 由管道分隔的串联字符串

我想循环遍历数组字符串并以NSString下列方式将它们添加到a :

NSMutableArray *emailsArray = [[NSMutableArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];

for (id email in emailsArray {
    NSString *emails = ??; 
}
Run Code Online (Sandbox Code Playgroud)

所以决赛NSString应该如下:

NSString *emails = @"One|Two|Three";
Run Code Online (Sandbox Code Playgroud)

iphone objective-c string-concatenation nsstring

2
推荐指数
1
解决办法
945
查看次数

将ms时间戳转换为NSString日期

我知道之前有很多iOS转换问题,但我找不到解决问题的方法.

我想将毫秒时间戳(即1299970800)转换为正确的人类可读日期,但是如何?

像"2011年3月12日"这样的东西就足够了.谢谢!

nsdate nsstring ios

2
推荐指数
1
解决办法
9866
查看次数