Skip to content

Instantly share code, notes, and snippets.

@urouro-net
Created July 21, 2020 14:18
Show Gist options
  • Save urouro-net/1a3d2873d073d1287cab27e2929d4412 to your computer and use it in GitHub Desktop.
Save urouro-net/1a3d2873d073d1287cab27e2929d4412 to your computer and use it in GitHub Desktop.
NSStringの全角文字のみ□に変換する
NSMutableString *convertedText = [[NSMutableString alloc] initWithCapacity:[text length]];
for (NSUInteger i = 0; i < [text length]; i++) {
NSString *character = [text substringWithRange:NSMakeRange(i, 1)];
if (![character canBeConvertedToEncoding:NSASCIIStringEncoding]) {
character = @"□";
}
[convertedText appendString:character];
}
NSLog(@"%@", convertedText);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment