标签: nsstring

URLWithString:返回nil

它可能很容易,但我似乎没有找到为什么URLWithString:在这里返回零.

//localisationName is a arbitrary string here
NSString* webName = [localisationName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
NSString* stringURL = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@,Montréal,Communauté-Urbaine-de-Montréal,Québec,Canadae&output=csv&oe=utf8&sensor=false&key=", webName];
NSURL* url = [NSURL URLWithString:stringURL];
Run Code Online (Sandbox Code Playgroud)

iphone url objective-c nsurl nsstring

93
推荐指数
3
解决办法
5万
查看次数

找出字符串是否为数字

我们如何检查字符串是否仅由数字组成.我从字符串中取出一个子字符串,并想检查它是否是一个数字子字符串.

NSString *newString = [myString substringWithRange:NSMakeRange(2,3)];
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c nsstring ios

91
推荐指数
7
解决办法
6万
查看次数

从一位数整数中生成一个两位数的字符串

即使整数小于10,我怎么能在一个字符串中有一个两位数的整数?

[NSString stringWithFormat:@"%d", 1] //should be @"01"
Run Code Online (Sandbox Code Playgroud)

string cocoa objective-c nsstring number-formatting

91
推荐指数
2
解决办法
4万
查看次数

如何将std :: string转换为NSString?

嗨,我正在尝试将标准std::string转换成一个,NSString但我没有太多运气.

我可以使用以下代码成功地从NSStringa 转换为astd::string

NSString *realm = @"Hollywood";
std::string REALM = [realm cStringUsingEncoding:[NSString defaultCStringEncoding]];
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试以下操作时,我收到编译时错误

NSString *errorMessage = [NSString stringWithCString:REALM encoding:[NSString defaultCStringEncoding]];
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

Cannot convert 'std::string' to 'const char*' in argument passing
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么吗?

提前致谢.

objective-c stdstring objective-c++ nsstring

90
推荐指数
4
解决办法
7万
查看次数

Objective-C中的字符串比较

我目前有一个网络服务器设置,我通过SOAP与我的iPhone应用程序进行通信.我正在返回一个包含GUID的字符串,当我尝试将其与另一个字符串进行比较时,我得到一些奇怪的结果.

为什么这不会开火?当然这两个字符串是匹配的吗?

NSString *myString = @"hello world";

if(myString == @"hello world")
    return;
Run Code Online (Sandbox Code Playgroud)

objective-c nsstring

86
推荐指数
3
解决办法
11万
查看次数

在目标c中的字符串数组中搜索字符串

我想在目标c中搜索字符串数组中的特定字符串.有人可以在这方面帮助我吗?

arrays objective-c nsstring ios

85
推荐指数
2
解决办法
9万
查看次数

检查UITextField的输入是否仅为数字

如何验证字符串输入UITextField?我想检查字符串是否为数字,包括小数点.

validation cocoa-touch objective-c nsstring uitextfield

82
推荐指数
6
解决办法
10万
查看次数

了解NSString比较

以下比较均评估为真:

1)

@"foo" == @"foo";
Run Code Online (Sandbox Code Playgroud)

2)

NSString *myString1 = @"foo";
NSString *myString2 = @"foo";
myString1 == myString2;
Run Code Online (Sandbox Code Playgroud)

但是,肯定有时候NSString使用等于运算符无法比较两个s,[myString1 isEqualToString:myString2]而是需要它.有人可以对此有所了解吗?

cocoa objective-c string-comparison nsstring

82
推荐指数
4
解决办法
10万
查看次数

ARC中的NSString到CFStringRef和CFStringRef到NSString?

我试图了解NSStringCFStringRefARC 获得一个正确的方法?同为去相反的方向,CFStringRefNSString在ARC?

在不造成内存泄漏的情况下执行此操作的正确方法是什么?

objective-c nsstring automatic-ref-counting toll-free-bridging

80
推荐指数
1
解决办法
4万
查看次数

不推荐使用sizeWithFont方法.boundingRectWithSize返回意外值

在iOS7中,sizeWithFont不推荐使用,因此我正在使用boundingRectWithSize(返回CGRect值).我的代码:

 UIFont *fontText = [UIFont fontWithName:[AppHandlers zHandler].fontName size:16];
                    // you can use your font.

 CGSize maximumLabelSize = CGSizeMake(310, 9999);

 CGRect textRect = [myString boundingRectWithSize:maximumLabelSize   
                             options:NSStringDrawingUsesLineFragmentOrigin
                             attributes:@{NSFontAttributeName:fontText}
                             context:nil];

 expectedLabelSize = CGSizeMake(textRect.size.width, textRect.size.height);
Run Code Online (Sandbox Code Playgroud)

textRect,我的尺寸大于我maximumLabelSize,尺寸与使用时不同sizeWithFont.我该如何解决这个问题?

objective-c nsstring uilabel ios7

80
推荐指数
3
解决办法
7万
查看次数