nsstring

Are NSStrings stored on the heap or on the stack and what is a good way to initialize one

百般思念 提交于 2019-11-30 09:18:05
I have 2 new questions: 1) Consider this line: NSString *myString = [[NSString alloc] initWithString: @"Value"]; There were two things I learned, but I would like confirmation: As I learned, the "alloc" message indicates that the instance of NSString will be stored in the "heap" memory. I understood also that primitive variables such as "chars" are stored in the "stack" memory. Does this mean that: the instance of NSString is stored in the heap memory; AND that this object has an iVar pointer (when the initWithString method was called) to the "Value" string of primitive "chars", which reside

Sort NSArray of NSStrings like Addressbook on iphone sort

给你一囗甜甜゛ 提交于 2019-11-30 09:07:44
I have an array of strings (names) and i would like to sort them like how the address book on the iphone sorts them eg: éli -> under E eg: àli -> under A eg: 4li -> under # any suggestions? You need to perform a diacritic insensitive comparison against the strings. NSString has a compare:options: method with an option of NSDiacriticInsensitiveSearch . NSArray *array = [NSArray arrayWithObjects:@"éli", @"bob", @"earl", @"allen", @"àli", @"aaron", nil]; NSArray *sorted = [array sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { return [(NSString*)obj1 compare:obj2 options

What is the most efficient way to count number of word in NSString without using regex?

陌路散爱 提交于 2019-11-30 09:07:25
问题 I am a bit new to Objective C and was wondering if there is a better way to count words in a string. ie: NSString *str = @"this is a string"; // return should be 4 words .. The way I now how to do it is by breaking the string into an array of words space (' ') character and count the array. Any advise will be appreciated! Thanks!! :) EDIT: For those of you who came here looking for answer; I found a similar post with an excellent reply. How to count words within a text string? 回答1: Unless you

how to add concatenate multiple NSString in one String in iphone

喜夏-厌秋 提交于 2019-11-30 09:02:00
I have 5 String i want that they must be store in singe NSString all the values separate with | sign NSString *first=@"Ali"; NSString *second=@"Imran"; NSString *third=@"AliImran"; NSString *fourth=@"ImranAli"; NSString *fifth=@"Ali Imran Jamshed"; I want to all these in single NSString to store and all values separated by given sign. NSArray *myStrings = [[NSArray alloc] initWithObjects:first, second, third, fourth, fifth, nil]; NSString *joinedString = [myStrings componentsJoinedByString:@"|"]; // release myStrings if not using ARC. you can try .... NSString *joinString=[NSString

NSString to wchar_t*?

送分小仙女□ 提交于 2019-11-30 08:45:48
问题 I can't seem to find a good built-in way to convert an NSString to wchar_t... any tips on how to do this? Anything Apple exposes on the NSString class is for c-strings (char*) or for unichars, but nothing for wchar*. 回答1: [urString cStringUsingEncoding:NSUTF16LittleEndianStringEncoding] wchar_t is compiler specific. Assuming you wan the Win32 wchar_t , then UTF16 little ending encoded will do it. For Unix wchar_t you may need the NSUTF32 encoding family, with your platform of choice endianess

iOS,一行代码进行RSA、DES 、AES、MD5加密、解密

不打扰是莪最后的温柔 提交于 2019-11-30 08:41:43
iOS,一行代码进行RSA、DES 、AES、MD5加密、解密 加密的Demo,欢迎下载 java端的加密解密,读者可以看我同事的这篇文章 http://www.jianshu.com/p/98569e81cc0b 最近做了一个移动项目,是有服务器和客户端类型的项目,客户端是要登录才行的,服务器也会返回数据,服务器是用Java开发的,客户端要同时支持多平台(Android、iOS),在处理iOS的数据加密的时候遇到了一些问题。起初采取的方案是DES加密,老大说DES加密是对称的,网络抓包加上反编译可能会被破解,故采取RSA方式加密。RSA加密时需要公钥和私钥,客户端保存公钥加密数据,服务器保存私钥解密数据。(iOS端公钥加密私钥解密、java端公钥加密私钥解密,java端私钥加密公钥解密都容易做到,iOS不能私钥加密公钥解密,只能用于验签)。 问题 问题1:iOS端公钥加密的数据用Java端私钥解密。 iOS无论使用系统自带的sdk函数,用mac产生的或者使用java的jdk产生的公钥和私钥,进行加密解密自己都可以使用。不过ios加密,java解密,或者反过来就不能用了。要么是无法创建报告个-9809或-50的错误,要么解出来是乱码。ios系统函数种只有用公钥加密,私钥解密的方式。而公钥加密每次结果都不同。 MAC上生成公钥、私钥的方法,及使用 1.打开终端

Objective-C creating a text file with a string

感情迁移 提交于 2019-11-30 08:26:57
I'm trying to create a text file with the contents of a string to my desktop. I'm not sure if I'm doing it right, I don't get errors but it doesn't work either... NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES); NSString *desktopDirectory=[paths objectAtIndex:0]; NSString *filename = [desktopDirectory stringByAppendingString: @"file.txt"]; [myString writeToFile:filename atomically:YES encoding: NSUTF8StringEncoding error: NULL]; megha //Method writes a string to a text file -(void) writeToTextFile{ //get the documents directory: NSArray *paths =

What is the different between NSCFString and NSConstantString?

与世无争的帅哥 提交于 2019-11-30 08:22:35
问题 I declare the object variable as a NSString But when I use the XCode to look into my object, I saw there are two type of String, it seems that the system automatically transfer to another: What are the different between them? Are they interchangeable to one and others. Also, what is the condition two change to another? Thanks. 回答1: They're both concrete subclasses of NSString . __NSCFString is one created during runtime via Foundation or Core Foundation, while __NSCFConstantString is either a

how to split strings in objective c

那年仲夏 提交于 2019-11-30 08:21:54
问题 How to split a string in objective-C? I am working on an short application that contains a date picker. I do display date get it from date picker and display it through a label. My main question is that how can I split the the date in to three separate strings? any one has idea about it? Thanks 回答1: You could use -[NSString componentsSeparatedByString:] or NSScanner to split the string, or use NSCalendar to extract the pieces of the date you're interested in. 回答2: Use something like

How to split a string with newlines

烈酒焚心 提交于 2019-11-30 08:00:29
I read from a csv file, and want to split the long string that I get using stringWithContentsOfFile, which is a multi line string, with individual lines representing rows in the csv file. How do I do this? Dipendra You can break the string into arrays of string and then manipulate as you want. NSArray *brokenByLines=[yourString componentsSeparatedByString:@"\n"] Just in case anyone stumbles across this question like I did. This will work with any newline characters: NSCharacterSet *separator = [NSCharacterSet newlineCharacterSet]; NSArray *rows = [yourString