nsstring

Auto suggest in UITextfield with comma separation

*爱你&永不变心* 提交于 2019-12-13 01:43:22
问题 The following code lets me auto suggest values typed into a UITextfield, by comparing it to an array of previously added string objects and show it in a UITableview. This works fine, but only for a single word. So now, can I modify the code in such a way, that after the user enters a comma, then starts typing again, I can search the same string array for suggestions again for the characters typed after the comma? - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:

How to represent NSString with '\336\362\340' value in appropriate encoding as normal text?

爷,独闯天下 提交于 2019-12-13 01:43:11
问题 I got strings like this from audio stream as titles: Þòà - Ïàäàòü I know that this string in russian. And I need to show it correctly in UILabel. I try this: NSData *data = [value dataUsingEncoding:NSNonLossyASCIIStringEncoding]; NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; Now goodValue contains next value: \336\362\340 - \317\340\344\340\362\374 Number of characters as I see the save with original. But how I should convert it into normal string

NSCaseInsensitiveSearch not works in rangeOfCharacterFromSet

一世执手 提交于 2019-12-13 01:33:52
问题 It seems that NSCaseInsensitiveSearch not works in NSString:rangeOfCharacterFromSet . Can someone explain why? is it correct behaviour? NSString *string = @"James Bond Always Rocks"; NSRange range = [string rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"J"] options:NSCaseInsensitiveSearch]; NSLog(@"range->%@",NSStringFromRange(range)); //This prints range->{0, 1} NSString *string = @"James Bond Always Rocks"; NSRange range = [string rangeOfCharacterFromSet:

Checking to see if an NSString contains characters from a different NSString

本小妞迷上赌 提交于 2019-12-13 01:17:57
问题 I am looking for a way to compare two strings and see if the second string contains a character (letter, number, other) listed in the first, let me explain: For example: Imagine a password with only digits and "*" are allowed: Reference chain (1): "*0123456789" NSString format, no NSArray Work chain (2) = "156/15615=211" NSString format, How do I know that my chain 2 contains 2 characters (/=) which are not in my chain 1? To simplify the management letters allowed, I do not want to use

NSURL object from initWithString gives -[NSURL length] error

爱⌒轻易说出口 提交于 2019-12-13 01:13:43
问题 I'm trying to find a file with a path, then delete it using the NSFileManager class. the [info objectForKey:UIImagePickerControllerMediaURL] does return a string, so I dont' understand why its failing on a valid parameter. NSError *error; NSFileManager *manager = [NSFileManager defaultManager]; NSURL *url = [[NSURL alloc] initWithString:[info objectForKey:UIImagePickerControllerMediaURL]]; if ([manager isDeletableFileAtPath: [info objectForKey:UIImagePickerControllerMediaURL]]) { BOOL success

Objective-c sockets - Can't correctly receive string in udp message

旧巷老猫 提交于 2019-12-13 01:04:51
问题 I am having troubles receiving the string I am sending with a UDP packet when this string is dynamically created (when i set its value equal to the one of another variable in my code). This problem does not present itself when, differently, I set a constant value to the string when this one is created. Here is the method i use for sending the string: - (void) sendUDPMessage { int sockfd; struct sockaddr_in server_addr; char myBroad[]="255.255.255.255"; struct hostent *hptr = gethostbyname

How to shorten an NSString that might include e.g. Emojis to the maximal length allowed for a HFS+ filename

眉间皱痕 提交于 2019-12-13 00:55:22
问题 Apples documentation says: [...] current file systems such as HFS+ (used by Mac OS X) allow you to create filenames with a 255-character limit [...] symbols may actually take up to the equivalent of nine English characters to store [...] This should be considered when attempting to create longer names. How do I limit the length of a NSString in a way that it is truly shorter than 255 characters, even when it includes symbols that might take more than one character to store? I add my current

How to convert NSString to ASCII value from String Value

耗尽温柔 提交于 2019-12-12 20:03:29
问题 if i have string value as a it should display as 65 and if it is b it should display ASCII equivalent 66 so on anyone please do help!!!! 回答1: NSString *string = @"A"; int asc = [string characterAtIndex:0]; 来源: https://stackoverflow.com/questions/10240555/how-to-convert-nsstring-to-ascii-value-from-string-value

Create NSData by interpreting NSString as hex digits

走远了吗. 提交于 2019-12-12 19:55:20
问题 Edit1: rob mayoff'answer is wonderful.And this is my own: -(NSData *)change:(NSString *)hexString { int j=0; Byte bytes[[hexString length]]; for(int i=0;i<[hexString length];i++) { int int_ch; unichar hex_char1 = [hexString characterAtIndex:i]; int int_ch1; if(hex_char1 >= '0' && hex_char1 <='9') int_ch1 = (hex_char1-48)*16; else if(hex_char1 >= 'A' && hex_char1 <='F') int_ch1 = (hex_char1-55)*16; else int_ch1 = (hex_char1-87)*16; i++; unichar hex_char2 = [hexString characterAtIndex:i]; int

NSString writeToFile with URL encoded string

余生长醉 提交于 2019-12-12 19:20:02
问题 I have a Mac application that keeps it's own log file. It appends info to the file using NSString's writeToFile method. One of the things that it logs are URL's of web services that it is interacting with. To encode the URL, I'm doing this: searchString = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)searchString, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 ); The app then appends searchString to the rest of the URL and writes it to the log file.