Questions tagged [nscharacterset]

An NSCharacterSet object represents a set of Unicode-compliant characters. NSString and NSScanner objects use NSCharacterSet objects to group characters together for searching operations, so that they can find any of a particular set of characters during a search. The cluster’s two public classes, NSCharacterSet and NSMutableCharacterSet, declare the programmatic interface for static and dynamic character sets, respectively.

103 questions
93
votes
17 answers

Remove all non-numeric characters from a string in swift

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…
Dan
  • 1,083
  • 1
  • 7
  • 12
71
votes
8 answers

Strip Non-Alphanumeric Characters from an NSString

I'm looking for a quick and easy way to strip non-alphanumeric characters from an NSString. Probably something using an NSCharacterSet, but I'm tired and nothing seems to return a string containing only the alphanumeric characters in a string.
Jeff Kelley
  • 18,594
  • 5
  • 67
  • 80
67
votes
6 answers

How to use stringByAddingPercentEncodingWithAllowedCharacters() for a URL in Swift 2.0

I was using this, in Swift 1.2 let urlwithPercentEscapes = myurlstring.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) This now gives me a warning asking me to use stringByAddingPercentEncodingWithAllowedCharacters I need to use a…
DogCoffee
  • 18,799
  • 9
  • 81
  • 114
55
votes
3 answers

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

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…
typeoneerror
  • 51,338
  • 32
  • 124
  • 213
26
votes
9 answers

NSArray from NSCharacterSet

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…
Saran
  • 6,052
  • 3
  • 37
  • 43
25
votes
3 answers

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

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…
qmlowery
  • 495
  • 2
  • 5
  • 7
19
votes
6 answers

stringByTrimmingCharactersInSet: is not removing characters in the middle of the string

I want to remove "#" from my string. I have tried NSString *abc = [@"A#BCD#D" stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"#"]]; But it still shows the string as "A#BCD#D" What could be wrong?
Sookcha
  • 217
  • 1
  • 2
  • 13
19
votes
2 answers

How to create a custom NSCharacterSet?

I’m using CharacterSet.urlQueryAllowed to add percent-encoding to a String. Some characters are not encoded the way I expected (i.e. & and ? are not changed). That being said, I had the idea to build a custom CharacterSet, ideally based on an…
ixany
  • 3,749
  • 8
  • 32
  • 55
18
votes
3 answers

Remove characters in NSCharacterSet from NSString

I have an NSCharacterSet which contains all the characters I want to remove from my NSString. How can I do that?
cschwarz
  • 1,195
  • 10
  • 23
9
votes
2 answers

Understanding the Use of invertedSet method of NSCharacterSet

So as I work my way through understanding string methods, I came across this useful class NSCharacterSet which is defined in this post quite well as being similar to a string excpet it is used for holding the char in an unordered set What is…
SESPROUL
  • 241
  • 3
  • 8
8
votes
1 answer

how to print characterSet in objective c?

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.
Ka-rocks
  • 764
  • 14
  • 27
7
votes
4 answers

Swift remove ONLY trailing spaces from string

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…
user1019042
  • 2,276
  • 8
  • 36
  • 75
6
votes
3 answers

Check strings for same characters in Objective-C

I have an array of strings, from which I would like to extract only those with unique character sets. (For example, "asdf" and "fdsa" would be considered redundant). This is the method I am currently using: NSMutableArray *uniqueCharSets =…
Rob
  • 9,433
  • 12
  • 52
  • 87
5
votes
1 answer

What makes up the category called "Marks" in NSCharacterSet?

I am reading up on NSCharacterSet. Can anyone tell me (with an example if possible) what characters are in the category "Marks"?
tranvutuan
  • 5,995
  • 8
  • 44
  • 82
5
votes
3 answers

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

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…
jwknz
  • 5,584
  • 13
  • 64
  • 105
1
2 3 4 5 6 7