nsstring

NSString from NSArray

妖精的绣舞 提交于 2019-12-05 09:03:06
I am trying to create a String from Array.But, there is condition to how it should be generated, as explained below. NSArray *array=[NSArray arrayWithObjects:@"Hello",@"World",nil]; [array componentsJoinedByString:@","]; This will output: Hello,World. But, if first Item is Empty,then is there way to receive the only second one. Hello , @"" => Hello @"" , World => World Hello , World => Hello,World Alladinian Another way to do this is to grab a mutable copy of the array and just remove non valid objects. Something like this perhaps: NSMutableArray *array = [[NSArray arrayWithObjects:@"",@"World

Casting or converting a char to an NSString in Objective-C

老子叫甜甜 提交于 2019-12-05 09:00:42
问题 How do I convert a char to an NSString in Objective-C? Not a null-terminated C string, just a simple char c = 'a' . 回答1: You can use stringWithFormat: , passing in a format of %c to represent a character, like this: char c = 'a'; NSString *s = [NSString stringWithFormat:@"%c", c]; 回答2: You can make a C-string out of one character like this: char cs[2] = {c, 0}; //c is the character to convert NSString *s = [[NSString alloc] initWithCString:cs encoding: SomeEncoding]; Alternatively, if the

Swift 3 error: [_SwiftValue pointSize] unrecognized selector sent to instance

不羁的心 提交于 2019-12-05 08:46:10
问题 I just migrated our project to swift 3 and see lots of crashes because of one issue: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_SwiftValue pointSize]: unrecognized selector sent to instance The reason for that error is the call to: [NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] What I noticed is that if I cast String to NSString and call boundingRectWithSize on it it will throw that error. It also seems to be

How do I get the substring between braces?

偶尔善良 提交于 2019-12-05 08:29:02
I have a string as this. NSString *myString = @"{53} balloons"; How do I get the substring 53 ? NSString *myString = @"{53} balloons"; NSRange start = [myString rangeOfString:@"{"]; NSRange end = [myString rangeOfString:@"}"]; if (start.location != NSNotFound && end.location != NSNotFound && end.location > start.location) { NSString *betweenBraces = [myString substringWithRange:NSMakeRange(start.location+1, end.location-(start.location+1))]; } edit : Added range check, thx to Keab42 - good point. Here is what I did. NSString *myString = @"{53} balloons"; NSCharacterSet *delimiters =

'(NSObject, AnyObject)' is not convertible to 'String'

空扰寡人 提交于 2019-12-05 08:17:13
How do I convert an object of type (NSObject, AnyObject) to the type String ? At the end of the first line of the method below, as String causes the compiler error: '(NSObject, AnyObject)' is not convertible to 'String' Casting street to NSString instead of String compiles, but I'm casting street to String because I want to compare it to placemark.name , which has the type String! , not NSString . I know name and street are optionals, but I'm assuming they're not nil for now because all the places returned from MKLocalSearch seem to have non-nil names and streets. func formatPlacemark

Objective C How to detect one or multiple spaces in a NSString

江枫思渺然 提交于 2019-12-05 08:14:29
问题 I have seen one answer for my task, but I couldnt find it now. I want to detect whether a string has empty word and contains at least "" or " " (two spaces" or more multiple spaces, OR not. If not, I would add this to Nsmutablearray. If yes with empty or at least one space, I would like it not to be written to mutablearray. How to solve this? EDIT 12 October 2011: Guys, thank you. Again I am sorry that I was unclear about my wish. I wanted to check if a string is empty or contains whitespaces

Two Dimension NSMutableArray help?

三世轮回 提交于 2019-12-05 07:42:11
问题 Ok, I have some C# code that looks like this and I was wondering what other developers would recommend if I am trying to put this into Objective-C. List<List<string>> meta_data I'm planning on using NSMutableArray but how to exactly get that two-dimensional array figured out is my problem, since there is no such thing as a multidimensional array in Objective-C. I'm new to using NSMutableArray , so I still need some help every now and then. I know I will just add string objects to the array

ios混淆方法名生成器

自闭症网瘾萝莉.ら 提交于 2019-12-05 06:07:16
有待整理,下记录一下。 #import <Foundation/Foundation.h> @interface DJRandomMethodName : NSObject /** 随机一个实例方法名*/ + (NSString *)randomMethodName; /** 随机一个类方法名*/ + (NSString *)randomClassName; @end // // DJRandomMethodName.m // Test0801 // // Created by 曹敬贺 on 16/8/1. // Copyright © 2016年 北京无限点乐科技有限公司. All rights reserved. // #import "DJRandomMethodName.h" typedef enum { DJClassName, DJMethodName }DJNameType; @interface DJRandomMethodName () //内存中缓存数组 @property (nonatomic, strong) NSMutableArray * memoryArray; //随机生成的名字组成的数组 @property (nonatomic, strong) NSMutableArray * namesArray; @end static dispatch

Appending unichar to NSMutableString

家住魔仙堡 提交于 2019-12-05 04:58:24
How do you append a unichar character to NSMutableString ? unichar c = 'T'; NSMutableString *s = [NSMutableString stringWithString:@"MyString"]; // want s to become "MyStringT" https://discussions.apple.com/thread/1679290 suggests: [s appendString:[NSString stringWithCharacters:&c length:1]]; Looks too long / complicated... Use [NSString appendFormat:], so for above: [s appendFormat:@"%C", c]; Enjoy! 来源: https://stackoverflow.com/questions/29357205/appending-unichar-to-nsmutablestring

Case insensitive compare against bunch of strings

梦想的初衷 提交于 2019-12-05 04:32:01
问题 What would be the best method to compare an NSString to a bunch of other strings case insensitive? If it is one of the strings then the method should return YES, otherwise NO. 回答1: Here's a little helper function: BOOL isContainedIn(NSArray* bunchOfStrings, NSString* stringToCheck) { for (NSString* string in bunchOfStrings) { if ([string caseInsensitiveCompare:stringToCheck] == NSOrderedSame) return YES; } return NO; } Of course this could be greatly optimized for different use cases. If, for