-
-
Save urouro-net/1a3d2873d073d1287cab27e2929d4412 to your computer and use it in GitHub Desktop.
NSStringの全角文字のみ□に変換する
This file contains 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
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