nscharacterset

How to strip special characters out of string?

三世轮回 提交于 2019-12-06 09:13:50
问题 I have a set with the characters I allow in my string: var characterSet:NSCharacterSet = NSCharacterSet(charactersInString: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ") I want to strip any other characters from a string so two unformatted data can be considered equal, like this: "American Samoa".lowercaseString == "american_samoa1".lowercaseString the lowercase version of these transformed strings would be "americansamoa" 回答1: Let's write a function for that (in swift 1.2). func

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

末鹿安然 提交于 2019-12-05 08:27:05
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%C%C%C", 0x0085, 0x000C, 0x2028, 0x2029]]; Now the bit that is the warning is: \t\n\r%C%C%C%C", 0x0085,

How to strip special characters out of string?

家住魔仙堡 提交于 2019-12-04 15:27:10
I have a set with the characters I allow in my string: var characterSet:NSCharacterSet = NSCharacterSet(charactersInString: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ") I want to strip any other characters from a string so two unformatted data can be considered equal, like this: "American Samoa".lowercaseString == "american_samoa1".lowercaseString the lowercase version of these transformed strings would be "americansamoa" mustafa Let's write a function for that (in swift 1.2). func stripOutUnwantedCharactersFromText(text: String, set characterSet: Set<Character>) -> String { return

Remove characters in NSCharacterSet from NSString

浪尽此生 提交于 2019-12-03 23:33:38
问题 I have an NSCharacterSet which contains all the characters I want to remove from my NSString. How can I do that? 回答1: If you're not too worried about efficiency, a simple way would be [[myString componentsSeparatedByCharactersInSet:myCharacterSet] componentsJoinedByString:@""] . Otherwise, you could run through the characters in a loop, appending ones that weren't in the set onto a new string. If you do it that way, remember to use an NSMutableString for your result as you're building it up.

How can I check if a string contains letters in Swift? [duplicate]

半城伤御伤魂 提交于 2019-12-03 06:48:08
问题 This question already has answers here : What is the best way to determine if a string contains a character from a set in Swift (10 answers) Closed 4 years ago . I'm trying to check whether a specific string contains letters or not. So far I've come across NSCharacterSet.letterCharacterSet() as a set of letters, but I'm having trouble checking whether a character in that set is in the given string. When I use this code, I get an error stating: 'Character' is not convertible to 'unichar' For

How can I check if a string contains letters in Swift? [duplicate]

好久不见. 提交于 2019-12-02 20:27:57
This question already has an answer here: What is the best way to determine if a string contains a character from a set in Swift 10 answers I'm trying to check whether a specific string contains letters or not. So far I've come across NSCharacterSet.letterCharacterSet() as a set of letters, but I'm having trouble checking whether a character in that set is in the given string. When I use this code, I get an error stating: 'Character' is not convertible to 'unichar' For the following code: for chr in input{ if letterSet.characterIsMember(chr){ return "Woah, chill out!" } } Victor Sigler You can

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

北慕城南 提交于 2019-12-02 19:56:05
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 enter anything but alpha numeric. Just need to add the "_" to those allowances. NSCharacterSet

how to print characterSet in objective c?

元气小坏坏 提交于 2019-12-01 16:59:53
i'm using GNUstep shell for programming objective-c. I'm able to convert string to a character set. But unable to print the converted character set in the console. Please tell me a way to print it. Thanks in advance. This will do the first 65536 characters in unicode, which will do for most situations. I believe unicode can go much higher (2^32?), but this would take much longer to log. + (void) logCharacterSet:(NSCharacterSet*)characterSet { unichar unicharBuffer[20]; int index = 0; for (unichar uc = 0; uc < (0xFFFF); uc ++) { if ([characterSet characterIsMember:uc]) { unicharBuffer[index] =

how to print characterSet in objective c?

孤人 提交于 2019-12-01 15:17:56
问题 i'm using GNUstep shell for programming objective-c. I'm able to convert string to a character set. But unable to print the converted character set in the console. Please tell me a way to print it. Thanks in advance. 回答1: This will do the first 65536 characters in unicode, which will do for most situations. I believe unicode can go much higher (2^32?), but this would take much longer to log. + (void) logCharacterSet:(NSCharacterSet*)characterSet { unichar unicharBuffer[20]; int index = 0; for

Remove all non-numeric characters from a string in swift

戏子无情 提交于 2019-11-30 10:24:12
问题 I have the need to parse some unknown data which should just be a numeric value, but may contain whitespace or other non-alphanumeric characters. Is there a new way of doing this in Swift? All I can find online seems to be the old C way of doing things. I am looking at stringByTrimmingCharactersInSet - as I am sure my inputs will only have whitespace/special characters at the start or end of the string. Are there any built in character sets I can use for this? Or do I need to create my own? I