Last active
January 18, 2021 23:51
-
-
Save unnamedd/b4882d8026cce716c85a to your computer and use it in GitHub Desktop.
Remove accents from words using Objective-C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
int main(int argc, char *argv[]) { | |
@autoreleasepool { | |
NSString *start = @"CéuÁbÊrtação"; | |
NSData *stringAsciiEncoded = [start dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; | |
NSString *simpleString = [[NSString alloc] initWithData:asciiEncoded encoding:NSASCIIStringEncoding]; | |
NSLog(@"Valor: %@", simpleString); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension String { | |
var sanitize: String? { | |
guard let data = data(using: .ascii, allowLossyConversion: true) else { return nil } | |
let value = String(data: data, encoding: .ascii) | |
return value | |
} | |
} | |
if let value = "CéuÁbÊrtação".sanitize { | |
print(value) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment