nsstring

UILabel, UIFont and UTF-8 Triangle

ε祈祈猫儿з 提交于 2019-11-28 09:28:47
I'd like to use "BLACK RIGHT-POINTING TRIANGLE" (U+25B6) as a part of my UILabel 's text. The label uses the system font ( UIFont 's systemFontOfSize: ). The problem is that my triangle is rendered as a fancy image, not a "black right-pointing triangle". Is it possible to see the plain version? Rudolf Adamkovič Based on: Unicode characters being drawn differently in iOS5 iOS 6 supports Unicode 6.1's variation selector , in this case \U0000FE0E . To answer my own question: @"\U000025B6" // a fancy triangle (mapped to Emoji) @"\U000025B6\U0000FE0E" // black right-pointing triangle For more

How do you detect words that start with “@” or “#” within an NSString?

瘦欲@ 提交于 2019-11-28 09:22:07
I'm building a Twitter iPhone app, and it needs to detect when you enter a hashtag or @-mention within a string in a UITextView. How do I find all words preceded by the "@" or "#" characters within an NSString? Thanks for your help! You can use NSRegularExpression class with a pattern like #\w+ (\w stands for word characters). NSError *error = nil; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"#(\\w+)" options:0 error:&error]; NSArray *matches = [regex matchesInString:string options:0 range:NSMakeRange(0, string.length)]; for (NSTextCheckingResult *match in

Replace letters in a string

若如初见. 提交于 2019-11-28 08:57:38
问题 Hello i have a problem that i don't know how to solve. The problem is that I even don't know how to google about it. I've already spent hours on the internet finding the solution, but didn't succeeded. The situation is like this: I have String, lets say: NSString *string = @"aąbcčdeęėfghiįjzž"; my result has to be like this: NSString *string = @"aabccdeeefghiujzz"; So if you understood i have to do this: replace ą with a replace č with c replace ė with e replace ę with e and so on.. Maybe

Subclassing NSString

﹥>﹥吖頭↗ 提交于 2019-11-28 08:54:26
问题 Using WSDL2ObjC I am getting lot of classes which are subclasses of NSString. I am finding it troublesome to initialize the NSString value of any object of those classes. Say my class looks like this : @interface mClass ; NSString { int value; } Now in my code I would like to use objects of mClass as both NSString and also want to use its attribute value which is an integer. How can I do that? I am trying to use code like this mClass *obj = [[mClass alloc] initWithString:@"Hello"]; But it's

Why dereferencing a NSString pointer is not necessary?

狂风中的少年 提交于 2019-11-28 08:45:47
In the example NSString *message = @"Hello"; message = @"World"; If message is just a pointer why don't I need to explicitly say whatever is in message is now equal to string or *message = @"World"; like in C? DISCLAIMER The discussion below gives a general idea on why you never dereferenciate a pointer to an object in Objective-C. However, concerning the specific case of NSString literals, this is not what's happening in reality. While the structure described below is still sound and it may work that way, what's actually happening is that the space for a string literal is allocated at compile

how can I convert string to an array with separator?

拜拜、爱过 提交于 2019-11-28 07:53:07
I have a string in the following format myString = "cat+dog+cow" I need to store each string separated by + in to a array. Eg: myArray[0] = cat myArray[1] = dog myArray[2] = cow Can anyone tell me the proper way to do this? componentsSeparatedByString: splits the string and return the result in an array. NSArray *myArray = [myString componentsSeparatedByString:@"+"]; [myArray objectAtIndex:0];//cat [myArray objectAtIndex:1];//dog [myArray objectAtIndex:2];//cow Try this.. NSArray *arr = [myString componentsSeparatedByString:@"-"]; [arr objectAtIndex:0];//Hai [arr objectAtIndex:1];//Welcome It

How to convert NSString HTML markup to plain text NSString?

你。 提交于 2019-11-28 07:40:16
Been searching the net for an example of how to convert HTML string markup into Plain text. I get my information from a feed which contains HTML , I then display this information in a Text View. does the UITextView have a property to convert HTML or do I have to do it in code. I tried: NSString *str = [NSString stringWithCString:self.fullText encoding:NSUTF8StringEndcoding]; but doesn't seem to work. Anyone got any ideas? You can do it by parsing the html by using NSScanner class - (NSString *)flattenHTML:(NSString *)html { NSScanner *theScanner; NSString *text = nil; theScanner = [NSScanner

Substring with range out of bounds?

谁说胖子不能爱 提交于 2019-11-28 07:39:32
问题 Okay, so this is a bit confusing (well to me). I have a string that has a single number I want out of it. I have surrounded this number with '/' so that I will be able to get that number out of it later. Here is how I am getting the number out of it: if ([MYSTRING hasSuffix:@"mp"]) { int start = 0; int end = 0; char looking = '/'; for(int i=0; i < MYSTRING.length; i++){ if (looking == [MYSTRING characterAtIndex:i]) { if (start == 0) { start = i; } else{ end = i + 1; } } } NSLog(@"%@",

Compare two NSStrings

会有一股神秘感。 提交于 2019-11-28 07:30:14
In my app there is a mechanism that requires that at a certain point two NSString s will be the same to do something; for some reason when I compare the two, even when they are the same, it still doesn't recognize that. The code is something like this: NSString * aString = [self someMethodThatGetsAString]; NSString * bString; BOOL areStringsTheSame = NO; while (areStringsTheSame != YES) { bString = [self someMethodThatTakesNSStringsFromAnArrey]; if (bString == aString) { areStringsTheSame = YES; { } I even inserted an NSLog() and made sure that at a certain point they were the same (and as far

NSString initWithData returns null

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 07:21:38
I am pulling data from a website via NSURLConnection and stashing the received data away in an instance of NSMutableData . In the connectionDidFinishLoading delegate method the data is convert into a string with a call to NSString's appropriate method: NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] The resulting string turns out to be a null. If I use the NSASCIIStringEncoding , however, I do obtain the appropriate string, albeit with unicode characters garbled up as expected. The server's Content-Type header does not specify the UTF-8 encoding, but I