nsstring

Replacing numbers in an NSString with Objects from NSArray

霸气de小男生 提交于 2019-12-11 17:53:53
问题 In a UITextView users can enter numbers formatted like {{1}} or {{177}} . In a preview field, much like here on SO I'd like to replace that pattern with a value from an NSArray, where the number corresponds to the row in the array. I have two ideas to solve this: Count all occurrences with an NSRegularExpression, loop through them and replace them. Create a word-array out of the NSString and loop through the array, replacing occurrences and put the NSString back together. Which of those two

iOS passing a string between two methods

天大地大妈咪最大 提交于 2019-12-11 17:14:09
问题 I have 4 choices assigned to 4 buttons. One of the choices is correct and it is assigned to the string "correctAnswerString" The 4 buttons call "action:@selector(submitAnswer:)" I want to be able to access the string "correctAnswerString" in the "submit Answer" method and compare if the button with the correct answer has been pressed. I believe this is done by creating an "@interface" in the .h file, but I don't know how to do it. Many appreciations for the help. The code is below: - (void)

Assign NSNull Object to NSString

依然范特西╮ 提交于 2019-12-11 16:12:12
问题 I'm writing an iOS App where i need to get data from a SQL-Database over mobile Services from Azure. After downloading the data I get a NSDictionary with all attributes from the SQL-Table. If an attribute is empty, the value is NSNull . Is there a way to pass NSNull to NSString without an IF-Statement (I don't want to have 20 if statements..)? 回答1: I wrote a category just for dealing with this issue. I used it with Core Data but it should help you, too. @interface NSDictionary (Extensions) -

字符串的介绍

霸气de小男生 提交于 2019-12-11 15:38:11
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 字符串的介绍 字符串在任何的开发中使用都是非常频繁的 OC和Swift中字符串的区别 在OC中字符串类型时NSString,在Swift中字符串类型是String OC中字符串 @"" ,Swift中字符串"" 使用 String 的原因 String 是一个结构体,性能更高 NSString 是一个 OC 对象,性能略差 String 支持直接遍历 Swift 提供了 String 和 NSString 之间的无缝转换 字符的定义 定义不可变字符串 // 1> 定义不可变字符串 : 使用let修饰 let str : String = "hello swift" // str = "hello Objective-C" 错误写法 定义可变字符串 // 2> 定义可变字符串 : 使用var修饰 var strM : String = "hello world" strM = "hello china" 字符串的使用 获取字符串的长度 获取字符集合,再获取集合的count属性 let count = str.characters.count 字符串拼接 两个字符串的拼接 let str1 = "Hello" let str2 = "World" let str3 = str1 + str2

06-Swift中的字符串

送分小仙女□ 提交于 2019-12-11 15:37:59
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 字符串的介绍 1 OC和Swift中字符串的区别 在OC中字符串类型时NSString,在Swift中字符串类型是String OC中字符串 @"" ,Swift中字符串"" 使用 String 的原因 String 是一个结构体,性能更高 NSString 是一个 OC 对象,性能略差 String 支持直接遍历 Swift 提供了 String 和 NSString 之间的无缝转换 2 字符串的使用 遍历字符串 // 1- 字符串的常规遍历 var str = "bu gu du de mei shi jia" for a in str.characters{ print("a") } 字符串和其他数据类型的拼接 // 2- 两个字符串的拼接 let a = "bu gu du de" var b = "mei shi jia" b = a + b 字符串的格式化 //列如时间格式化 4:32---->04:32 let min = 4 let second = 32 let t = String(format: "%02d:%02d" ,arguments: [min,second]) 两个字符串的拼接 let a = "bu gu du de" var b = "mei shi jia" b = a +

NSString length with flag emojis

旧巷老猫 提交于 2019-12-11 13:59:50
问题 I'm trying to get the length of an NSString that contains a bunch of emojis, including the flag characters. Now I know how to get the length of a string containing emojis: __block NSInteger length = 0; [string enumerateSubstringsInRange:range options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { length++; }]; However, "NSStringEnumerationByComposedCharacterSequences" doesn't work in this case.

Is alloc+initWithString: same as copy?

妖精的绣舞 提交于 2019-12-11 13:36:57
问题 Basically, the question is - are the following essentially the same? NSString *value1 = ...; NSString *value2 = [[NSString alloc] initWithString:value1]; and NSString *value1 = ...; NSString *value2 = [value1 copy]; 回答1: Conceptually, yes. However, there is one difference: alloc always creates a new string, whereas copy may return the same string. In particular, immutable objects, such as immutable strings, are likely respond to copy by returning themselves rather than creating and returning

Getting Wikipedia Article Summary using NSScanner Problem

时光怂恿深爱的人放手 提交于 2019-12-11 13:29:19
问题 I am trying to get the summary of an article and download it as a string. This works great with some articles, but the wikipedia website is inconsistent. So NSScanner fails pretty often while it works fine for other articles. Here's my NSScanner implementation: NSString *separatorString = @"<table id=\"toc\" class=\"toc\">"; NSScanner *aScanner = nil; NSString *container = nil; NSString *muString = [NSString stringWithString:@"</table>"]; aScanner = [NSScanner scannerWithString:string];

how to replace one substring with another in Objective C?

谁都会走 提交于 2019-12-11 12:48:11
问题 I want to replace an NSString substring with another substring in Objective C. I know how to locate the substring I want to replace: NSRange range = [string rangeOfString:substringIWantToReplace]; NSString *substring = [string substringFromIndex:NSMaxRange(range)]; But when it comes to actually removing/replacing it, I'm a little confused. Do I follow the C++ method at Replace substring with another substring C++? Or the C method at how to replace substring in c?? There's a related question

How to find a particular text in UITextField?

*爱你&永不变心* 提交于 2019-12-11 12:07:37
问题 In my iPhone app I have a UITextField ans text field value is being taken into an NSString , I want to find if a particular character " is typed in that How can I do that? UITextField *textField; NSString *String=textField.text; -(IBAction)FindCharecter:(id)sender { // if String Contain ",then i wish to print @"Found symbol" } 回答1: UITextField *textField; NSString *string=textField.text; if ([string rangeOfString:@"\""].location == NSNotFound) { NSLog(@"string does not \""); } else { NSLog(@