nsstring

how to add concatenate multiple NSString in one String in iphone

亡梦爱人 提交于 2019-11-29 13:15:37
问题 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. 回答1: NSArray *myStrings = [[NSArray alloc] initWithObjects:first, second, third, fourth, fifth, nil]; NSString *joinedString = [myStrings

DOM based XML Parser for Objective-C

余生颓废 提交于 2019-11-29 12:54:32
/*--> */ /*--> */ 当前Objective-C可用的XML解析器比较多(可以到我的文章 《介绍两种常用的XML解析方式(NSXMLParser & GDataXMLNode)》 和 《如何选择你的iPhone XML解析器》 中了解)。想了解DOM相关知识可参看 W3School 。 其实Google的 GDataXMLNode 其实也是一种基于DOM结构的XML解析器,GDataXMLNode只是是对 libxml XML解析库进行了Objective-C的封装。在大多是情况下GDataXMLNode完全可以满足我们解析XML格式文件的需求,也能够对文档XML文件结构进行修改(可能需要自己实现一些东西)。但是GDataXMLNode存在一个问题,就是GDataXMLNode中的每一个Node节点对象对应一个libxml中的xmlNodePtr的结构体,但这种关系并不是一一对应的,也就是你不能通过xmlNodePtr的结构体对应到响应的Node对象,GDataXMLNode中你可以发现每次取相同位子的一个节点,都是对应不同的Node对象,虽然这些Node对象内容是相同的。以为GDataXMLNode中每次都是通过xmlNodePtr去创建一个新的Node对象,这对于只关注文档内容的解析是没有影响的,但是如果涉及到大量节点的操作、遍历,可能会有些麻烦。

NSBundle介绍

蹲街弑〆低调 提交于 2019-11-29 12:33:43
bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 对应bundle,cocoa提供了类NSBundle. 我们的程序是一个bundle. 在Finder中,一个应用程序看上去和其他文件没有什么区别. 但是实际上它是一个包含了nib文件,编译代码,以及其他资源的目录. 我们把这个目录叫做程序的main bundle bundle中的有些资源可以本地化.例如,对于foo.nib,我们可以有两个版本: 一个针对英语用户,一个针对法语用户. 在bundle中就会有两个子目录:English.lproj和French.lproj,我们把各自版本的foo.nib文件放到其中. 当程序需要加载foo.nib文件时,bundle会自动根据所设置的语言来加载. 我们会在16章再详细讨论本地化 通过使用下面的方法得到程序的main bundle NSBundle *myBundle = [NSBundle mainBundle]; 一般我们通过这种方法来得到bundle.如果你需要其他目录的资源,可以指定路径来取得bundle NSBundle *goodBundle; goodBundle = [NSBundle bundleWithPath:@"~/.myApp/Good.bundle"];

Object 转 Json (针对父类和数组)

我怕爱的太早我们不能终老 提交于 2019-11-29 12:33:41
原文地址: http://www.pluto-y.com/object-to-json/ 该文章是针对那些不想用第三方框架,却想做到OC转Json的朋友的文章。 关于普通的OC转Json的资料已经非常多了,可是对于其中的转换还是存在一些缺陷,关于其中的缺陷也会在接下来的文章中提到。不过首先我们先看看网络上经常看到的实现方法和实现,并且针对其中的缺陷进行逐一的填补。 首先先看看网络上的实现方法 刚开始做项目的时候暂时还不想用第三方框架,于是就去搜索了如何OC转Json的资料,刚开始哪来用的时候主要是通过以下这些方法来实现 首先第一个方法是下面这个方法。该方法是用于遍历对象中的属性,将其转换为 NSDictionary 。 + ( NSDictionary *)getObjectData:( id )obj { NSMutableDictionary *dic = [ NSMutableDictionary dictionary]; unsigned int propsCount; objc_property_t *props = class_copyPropertyList([obj class], &propsCount); for ( int i = 0 ;i < propsCount; i++) { objc_property_t prop = props[i];

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

强颜欢笑 提交于 2019-11-29 12:31:24
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? Unless you're going to be doing it hundreds of times a second, I would just opt for the readable solution, something

Objective-C - Converting NSString to a C string [duplicate]

限于喜欢 提交于 2019-11-29 12:26:49
Possible Duplicate: objc warning: “discard qualifiers from pointer target type” I'm having a bit of trouble converting an NSString to a C string. const char *input_image = [[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String]; const char *output_image = [[[NSBundle mainBundle] pathForResource:@"iphone_resized" ofType:@"png"] UTF8String]; const char *argv[] = { "convert", input_image, "-resize", "100x100", output_image, NULL }; // ConvertImageCommand(ImageInfo *, int, char **, char **, MagickExceptionInfo *); // I get a warning: Passing argument 3 'ConvertImageCommand'

Replacing multiple characters in NSString by multiple other characters using a dictionary

别说谁变了你拦得住时间么 提交于 2019-11-29 12:13:27
I would like to replace some characters in my string, by other characters, using a dictionary. For instance, every "a" should be replaced by "1", and every "1" should be replaced by "9". What I don't want is every "a" to be replaced twice, ending up with a "9". Every character must be replaced just once. I got this working using the following code, but I feel like it can be done more efficient. Is this really the best I can do, or can you help me improve my code? NSDictionary *replacements = [NSDictionary dictionaryWithObjectsAndKeys: // Object, Key, @"1", @"a", @"2", @"b", @"3", @"c", @"9", @

NSJSONSerialization and Emoji

百般思念 提交于 2019-11-29 11:53:27
I'm currently trying to POST some JSON containing emojis to a python API. I tried feeding the NSJSONSerialization directly with the string containing the emojis from my UITextField but the serializer crashed with no meaningful explanation. Afterwards I tried to do some format conversion and ended up with something like this: NSString *uniText = mytextField.text; NSData *msgData = [uniText dataUsingEncoding:NSNonLossyASCIIStringEncoding]; NSString *goodMsg = [[NSString alloc] initWithData:msgData encoding:NSUTF8StringEncoding] ; This basically works except that the resulting UTF-8 is kinda

Is there a way to use NSString stringByFoldingWithOptions to unfold the single French 'œ' character into 'oe'?

匆匆过客 提交于 2019-11-29 11:32:56
For a diacritics-agnostic full text search feature, I use the following code to convert accented characters like é or Ö into their lowercase non-accented form e and o [[inputString stringByFoldingWithOptions: NSCaseInsensitiveSearch + NSDiacriticInsensitiveSearch + NSWidthInsensitiveSearch locale: [NSLocale currentLocale]] lowercaseString]; This works. However, I found no way to convert special characters whose base form consists of multiple characters like the French œ (as in "sœur") or the German ß (as in 'Fluß'). I would like to convert them into oe and ss respectively. I found no flag for

How can I use the \\t [tab] operator to format a NSString in columns?

放肆的年华 提交于 2019-11-29 11:02:35
I would like to find a way to format a NSString like this: Name: John Location: Unknown Type: Unknown Status: Unknown Right now I'm using this code to do it but the result is quite different: The code: serializedValue = [serializedValue stringByAppendingFormat:@"%@:\t\t%@\n",title, value]; Where title is the left column and value is the second one. The result: Name: John Location: Unknown Type: Unknown Status: Unknown Now, as you can see, adding always a constant number of tabs (\t), 2 in my case, doesn't do the trick, because some words in the left column are longer and some are shorter. I'm