nscharacterset

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

♀尐吖头ヾ 提交于 2019-11-30 06:54:36
问题 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? 回答1: You could try NSString *modifiedString = [yourString stringByReplacingOccurrencesOfString:@"#" withString:@""]; 回答2: stringByTrimmingCharactersInSet removes characters from the beginning and end of your string, not from any place in it For your purpose use

Remove all non-numeric characters from a string in swift

我们两清 提交于 2019-11-28 16:57:16
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 was hoping there would be something like stringFromCharactersInSet() which would allow me to specify

Strip Non-Alphanumeric Characters from an NSString

纵饮孤独 提交于 2019-11-27 11:04:41
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. We can do this by splitting and then joining. Requires OS X 10.5+ for the componentsSeparatedByCharactersInSet: NSCharacterSet *charactersToRemove = [[NSCharacterSet alphanumericCharacterSet] invertedSet]; NSString *strippedReplacement = [[someString componentsSeparatedByCharactersInSet:charactersToRemove] componentsJoinedByString:@""]; In Swift, the

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

吃可爱长大的小学妹 提交于 2019-11-27 06:51:59
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 NSCharacterSet as an argument, but there are so many and I cannot determine what one will give me the same outcome as the previously used method. An example URL I want to use will be like this http://www.mapquestapi.com/geocoding/v1/batch?key=YOUR_KEY_HERE&callback=renderBatch&location=Pottsville,PA&location=Red Lion&location=19036&location=1090 N

Strip Non-Alphanumeric Characters from an NSString

 ̄綄美尐妖づ 提交于 2019-11-27 04:02:31
问题 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. 回答1: We can do this by splitting and then joining. Requires OS X 10.5+ for the componentsSeparatedByCharactersInSet: NSCharacterSet *charactersToRemove = [[NSCharacterSet alphanumericCharacterSet] invertedSet]; NSString *strippedReplacement = [

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

怎甘沉沦 提交于 2019-11-26 12:57:00
问题 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 NSCharacterSet as an argument, but there are so many and I cannot determine what one will give me the same outcome as the previously used method. An example URL I want to use will be like this http://www.mapquestapi.com/geocoding/v1/batch?key=YOUR

NSArray from NSCharacterSet

☆樱花仙子☆ 提交于 2019-11-26 11:21:01
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? 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" (characters > U+FFFF, e.g. U+10400 DESERET CAPITAL LETTER LONG I). NSCharacterSet *charset =