nsstring

Replace character in NSMutableAttributedString

北慕城南 提交于 2019-12-10 21:48:14
问题 This works for a regular NSString : NSString *newString = [myString stringByReplacingOccurrencesOfString:@"," withString:@""]; But there is no such method for NSMutableAttributedString . How could I remove all instances of a comma in an NSMutableAttributedString ? 回答1: let attrString = NSMutableAttributedString(string: "Hello <b>friend<b>") attrString.mutableString.replaceOccurrencesOfString("<b>", withString: "", options: NSStringCompareOptions.CaseInsensitiveSearch, range: NSRange(location:

Verify the existence of a word in an NSString

扶醉桌前 提交于 2019-12-10 21:44:08
问题 I searched a bit, but couldn't find an answer to this (probably very simple) question. I have an NSString, and I'd like to check if it contains a word. Something like this: NSString *sentence = @"The quick brown fox"; NSString *word = @"quack"; if ([sentence containsWord:word]) { NSLog(@"Yes it does contain that word"); } Thanks. 回答1: The following should work: NSString *sentence = @"The quick brown fox"; NSString *word = @"quack"; if ([sentence rangeOfString:word].location != NSNotFound) {

Capitalise first letter of every sentence

夙愿已清 提交于 2019-12-10 21:39:43
问题 How do I capitalise the first letter of every sentence in a string? Should I use .capitalisedString ? 回答1: You can enumerate String per sentences by using NSStringEnumerationOptions.BySentences . But it detect a "sentence" only if the first character is upper-cased. So, This may not be perfect, but you can try this: import Foundation let text:String = "lorem ipsum dolor elit, sed aliqfuas. imfs enim ad veniam, quis nostrud consequat? duis aute irure dolor in pariatur." var result = "" text

NSDate Formatting

早过忘川 提交于 2019-12-10 21:25:45
问题 I have a date string as follows: "Fri, 17 Jun 2011 19:20:51 PDT" which I need to parse into an NSDate format. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"EEE, d MM YYYY HH:mm:ss zzz"]; NSDate *date = [dateFormatter dateFromString:currentPubDate ]; [dateFormatter release]; The code doesn't appear to be working and I am not sure why. I have looked into the issue but searching through forums etc and can't seem to find an answer. I do believe it

Search in a NSString for words that begin with specific text and end with a "

独自空忆成欢 提交于 2019-12-10 21:06:58
问题 I have a NSString that contains the html code of a webpage. Now, how do i search on the whole string for all the words that start with 'data-src="http://' and end with a " ? I'll save them in an array. My string is called urlPage PS: i dont want the words to have the 'data-src="http://' and " . I just want the words between these 2 回答1: Here is some example code: NSString *string; NSString *pattern; NSRegularExpression *regex; string = @" aa data-src=\"http://test1\" cd data-src=\"http:/

Name and size from NSFont

家住魔仙堡 提交于 2019-12-10 20:31:45
问题 i've tried to find something in the Internet, but right now I don't have an answer, so it would be great if you can help me! So far I have a NSFont object, but I would like the name (as NSString) and size of the font, so I can output that! It's like [NSFont fontWithName:@"Menlo" size:11]; only backwards, so I get the name "Menlo" and as size 11. Thanks for help! Xcoder from Germany 回答1: The name and size of NSFont are variables with setters and getters ( @property ) so you can easily get them

Implicit conversion of a non-Objective-C pointer type 'char *' to 'NSString *' is disallowed with ARC

ⅰ亾dé卋堺 提交于 2019-12-10 20:10:54
问题 For the following line of code I am getting the error below: for (UILabel *label in labels) { label.text = label.tag - 100 > someMutableString.length ? "" : "*"; } The error states: Implicit conversion of a non-Objective-C pointer type 'char *' to 'NSString *' is disallowed with ARC My variable "someMutableString" is of type NSMutableString. How do I fix in my particular case? 回答1: The problem is that your string literals are "" and "*" which are both C-style strings ( const char* ). So the

How to capitalize first word in every sentence with Swift

你离开我真会死。 提交于 2019-12-10 19:04:55
问题 By taking into account of user locale, how can I capitalize the first word of each sentence in a paragraph? What I want to achieve is no matter the case inside the sentence, the first letter of each word will be uppercase and the rest will be lowercase. I can do only one sentence by first converting everything to lower case, then get first letter and make uppercase and finally add them up together. My question is different than How to capitalize each word in a string using Swift iOS since I

NSString replace unicode characters

笑着哭i 提交于 2019-12-10 18:49:11
问题 I'w working with a server and I have to download text to my iOS application. Only problem : all characters like "é à ç" are replaced by "\U008" for example. Is there a way to fix this problem, to replace this code by the right character ? 回答1: Try to parse the received text (textToParse variable) with this one: NSString *encodedString = textToParse; NSString *decodedString = [NSString stringWithUTF8String:[encodedString cStringUsingEncoding:[NSString defaultCStringEncoding]]]; 回答2: I tested

Why doesn't the storyboard reflect the text attributes I've set to a UILabel using the attributes inspector panel?

半世苍凉 提交于 2019-12-10 18:12:29
问题 I have a UILabel on the storyboard. The default text reads "Label". I then go to the attributes inspector and select the Attributed text style. When I click on the Text field I am presented with several fonts to choose from in a new window. I see that the default text in this case has been set to Helvetica size 17.0. When looking through the fonts presented I decide to use one called ORC A Std. This is part of the fixed width family. Since I want to use this font, I go back into my attributes