nscharacterset

How to use NSLineSeparatorCharacter and NSParagraphSeparatorCharacter?

荒凉一梦 提交于 2020-01-17 05:06:12
问题 I wonder how I can use the constants NSLineSeparatorCharacter and NSParagraphSeparatorCharacter as a parameter to a function instead of hard coding \n . - (id)initWithSeparator:(id)separator { m_separator = separator; } What would be the correct parameter type and what conversion needs to be done? Depending on the file contents I wish to call the function like ... Object* obj = [[Object alloc] initWithSeparator:NSLineSeparatorCharacter]; ... or ... Object* obj = [[Object alloc]

NSCharacterSet: How do I add “_” to alphanumericCharacterSet text restriction?

老子叫甜甜 提交于 2019-12-31 10:06:10
问题 Building an NSCharacter set to restrict a UITextField for entering user names. I want the user to be able to also enter an underscore (so [A-Za-z0-9_]) but alphanumericCharacterSet does not include it. Is there a way to specify a range like that in short form? I see + (id)characterSetWithRange:(NSRange)aRange , but I'm not really understanding how that would work. I've got a simple UITextField sub-class that I pass the character set to. The restriction works fine and doesn't allow the user to

NSArray from NSCharacterSet

ぐ巨炮叔叔 提交于 2019-12-17 02:14:30
问题 Currently I am able to make array of Alphabets like below [[NSArray alloc]initWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z",nil]; Knowing that is available over [NSCharacterSet uppercaseLetterCharacterSet] How to make an array out of it? 回答1: The following code creates an array containing all characters of a given character set. It works also for characters outside of the "basic multilingual plane"

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:

Removing Character issue from NSString in iPhone

无人久伴 提交于 2019-12-12 21:00:50
问题 I have a string with value "€100,000,000". I want to remove the '€' and ',' at the same time. I am try to use [NSCharacterSet symbolSet] but this method only removes the '€' without removing the ','. 回答1: You can try: -(NSString*)cleanString:(NSString*)str NSString *string = [NSString stringWithString:str]; NSCharacterSet *charSet = [NSCharacterSet characterSetWithCharactersInString:@"€,"]; string = [string stringByTrimmingCharactersInSet:charSet]; return string; } 回答2: Use this: string =

EXC BAD ACCESS while creating a new CharacterSet

社会主义新天地 提交于 2019-12-11 04:29:45
问题 I'm trying to write a slugging function which involves stripping out any punctuation characters except for hyphens. I thought the best way to do this would be to create a new CharacterSet as follows: import Foundation extension CharacterSet { func subtracting(charactersIn string: String) -> CharacterSet { let unwantedCharacters = CharacterSet(charactersIn: string) return self.subtracting(unwantedCharacters) } } let punctuationCharactersExcludingHyphen = CharacterSet.punctuationCharacters

What is differnce between NSString and NSCharacterset?

徘徊边缘 提交于 2019-12-10 22:08:19
问题 I studying NSCharacterset class. NSString and NSCharacterset look like similar class. Who can explain difference between NSString and NSCharacterset? When use NSCharacterset? Thanks your help.. 回答1: An NSString object represents a string of ordered characters (text). An NSCharacterSet object represents a set of characters in no particular order. It is often much quicker to determine whether a character is a member of an NSCharacterSet than an NSString. You can't use an NSCharacterSet object

Swift remove ONLY trailing spaces from string

荒凉一梦 提交于 2019-12-10 12:57:15
问题 many examples in SO are fixing both sides, the leading and trailing. My request is only about the trailing. My input text is: " keep my left side " Desired output: " keep my left side" Of course this command will remove both ends: let cleansed = messageText.trimmingCharacters(in: .whitespacesAndNewlines) Which won't work for me. How can I do it? 回答1: A quite simple solution is regular expression, the pattern is one or more( + ) whitespace characters( \s ) at the end of the string( $ ) let

How to Print the characterset of a Font?

不想你离开。 提交于 2019-12-08 02:45:27
问题 I have downloaded a font from the internet. Now I want to Print the Characterset of that font. I got the CFCharacterSetRef of that font. But I don't know how to print that CFCharacterSetRef. This is my coding. NSString *fontFilePath=@"/Volumes/Work/Mac/Fonts/FONT FOLDER/AngelicWar"; CFStringRef aCFString = (CFStringRef)fontFilePath; CTFontRef fontRef = CTFontCreateWithName(aCFString, 0.0,NULL); CFCharacterSetRef charRef=CTFontCopyCharacterSet (fontRef); For Printing the

NSCharacter Set uses int's but i need unassigned short?

杀马特。学长 韩版系。学妹 提交于 2019-12-07 04:07:00
问题 I am using MWFeedParser to add a feed into my app. Now the framework passes date's and I it has a few warnings mainly due to older type of code. Now there are 4 warnings left which are all the same and technically I can fix them and remove them so that the warnings are gone, but then I get left with the app not working properly. The code concerning is: // Character sets NSCharacterSet *stopCharacters = [NSCharacterSet characterSetWithCharactersInString:[NSString stringWithFormat:@"< \t\n\r%C