nsstring

Formatting html tags in Objective-C

痞子三分冷 提交于 2019-12-02 17:57:49
问题 I am reading an data from an XML file for my iPhone application. This data contains html tags such as <p></p> <strong> <B> , etc in it. By using NSString class can i remove these tags and format the display of the text as needed. For example, if text inside the <p> </p> i want to display it in next paragraph. Is it possible? Please suggest. Any help would be appreciated. -Sathiya 回答1: Why not leave the formatting in place, and use either a UIWebView to display the text or a TTStyledTextLabel

How to make an NSString path (file name) safe

自古美人都是妖i 提交于 2019-12-02 17:53:07
I'm using very tricky fighting methods :) to make a string like Fi?le*/ Name safe for using as a file name like File_Name . I'm sure there is a cocoa way to convert it. And I'm sure the best place to ask is here :) Thank you! Unless you're explicitly running the shell or implicitly running the shell by using a function such as popen or system , there's no reason to escape anything but the pathname separator. You may also want to enforce that the filename does not begin with a full stop (which would cause Finder to hide the file) and probably should also enforce that it is not empty and is

NSString stringWithFormat and NSArray [duplicate]

牧云@^-^@ 提交于 2019-12-02 17:35:23
问题 This question already has answers here : How to create a NSString from a format string like @“xxx=%@, yyy=%@” and a NSArray of objects? (13 answers) Closed 2 years ago . I need a method for generating string from the format-string and it's arguments inside NSArray but I did't find any working solution on the StackOverflow. They don't build nor throw exceptions (first, second). 回答1: So I write my solution and I want to share it with you. @implementation NSString (AX_NSString) + (instancetype

How to get a single NSString character from an NSString

一世执手 提交于 2019-12-02 17:13:54
I want to get a character from somewhere inside an NSString. I want the result to be an NSString. This is the code I use to get a single character at index it: [[s substringToIndex:i] substringToIndex:1] Is there a better way to do it? This will also retrieve a character at index i as an NSString, and you're only using an NSRange struct rather than an extra NSString. NSString * newString = [s substringWithRange:NSMakeRange(i, 1)]; joshualmf If you just want to get one character from an a NSString, you can try this. - (unichar)characterAtIndex:(NSUInteger)index; Used like so: NSString

How to check if NSString is contains a numeric value?

隐身守侯 提交于 2019-12-02 17:07:24
I have a string that is being generate from a formula, however I only want to use the string as long as all of its characters are numeric, if not that I want to do something different for instance display an error message. I have been having a look round but am finding it hard to find anything that works along the lines of what I am wanting to do. I have looked at NSScanner but I am not sure if its checking the whole string and then I am not actually sure how to check if these characters are numeric - (void)isNumeric:(NSString *)code{ NSScanner *ns = [NSScanner scannerWithString:code]; if (

How to use drawInRect:withAttributes: instead of drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment: in iOS 7

寵の児 提交于 2019-12-02 17:02:01
This method is deprecated in iOS 7.0: drawAtPoint:forWidth:withFont:fontSize:lineBreakMode:baselineAdjustment: Now use drawInRect:withAttributes: instead. I can't find the attributeName of fontSize and baselineAdjustment. Edit Thanks @Puneet answer. Actually, I mean if there doesn't have these key, how to implement this method in iOS 7? Like below method: + (CGSize)drawWithString:(NSString *)string atPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font fontSize:(CGFloat)fontSize lineBreakMode:(IBLLineBreakMode)lineBreakMode baselineAdjustment:(UIBaselineAdjustment

iOS: Objective-C creating class property error: Use of undeclared identifier

谁说我不能喝 提交于 2019-12-02 16:24:36
问题 I'm trying to use class property following this example. But I'm getting the following error:"Use of undecleared identifier '_myProperty'". Here is my implementation: @interface myClass() @property (class,strong,nonatomic) NSString *myProperty; @end + (NSString*)myProperty { if (!_myProperty) { } return [NSString new]; } Why I'm getting this error? or any of you knows a work around this? I'll really appreciate your help 回答1: Class properties don't get synthesized in Objective-C. You have to

NSString boundingRectWithSize returning unnecessarily tall height

与世无争的帅哥 提交于 2019-12-02 15:56:44
When using [NSString boundingRectWithSize:options:attributes] the size of the rect that is returned is taller than I would expect for certain strings. The height returned appears to represent the maximum possible height of a string with the given attributes, rather than the height of the string itself. Assuming the same attributes and options, the height returned for the string " cars " is the same height returned for the string " ÉTAS-UNIS " (note the accent on the E). I would have expected boundingRectWithSize to only consider the characters in the given string, which in my opinion would

How to capitalize the first word of the sentence in Objective-C?

时间秒杀一切 提交于 2019-12-02 15:10:01
I've already found how to capitalize all words of the sentence, but not the first word only. NSString *txt =@"hi my friends!" [txt capitalizedString]; I don't want to change to lower case and capitalize the first char. I'd like to capitalize the first word only without change the others. Johan Kool Here is another go at it: NSString *txt = @"hi my friends!"; txt = [txt stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[txt substringToIndex:1] uppercaseString]]; For Swift language: txt.replaceRange(txt.startIndex...txt.startIndex, with: String(txt[txt.startIndex])

NSString unicode encoding problem

余生长醉 提交于 2019-12-02 15:08:49
问题 I'm having problems converting the string to something readable . I'm using NSString *substring = [NSString stringWithUTF8String:[symbol.data cStringUsingEncoding:NSUTF8StringEncoding]]; but I can't convert \U7ab6\U51b1 into ' It shows as 窶冱 which is what I don't want, it should show as an '. Can anyone help me? 回答1: it is shown as a ’ That's character U+2019 RIGHT SINGLE QUOTATION MARK. What has happened is you've had the character sequence ’s submitted to you, in the UTF-8 encoding, which