emoj过滤 ios
2016-07-22 16:59:00 weixin_30730151 阅读数 1
+(NSString *)convertSimpleUnicodeStr:(NSString *)inputStr{
    
    int  unicodeIntValue= strtoul([inputStr UTF8String],0,16);
    
    UTF32Char inputChar = 128535; // unicodeIntValue ;
    
    inputChar = NSSwapHostIntToLittle(inputChar);
    
    NSString *sendStr = [[NSString alloc] initWithBytes:&inputChar length:4 encoding:NSUTF32LittleEndianStringEncoding];
    
    NSLog(@"%@",sendStr);
    
    return sendStr;
}

 

转载于:https://www.cnblogs.com/heml/p/5695788.html

2016-08-25 10:06:00 weixin_34416649 阅读数 6

还是直接上代码吧

//从http://stackoverflow.com/a/22956420搬运
- (BOOL)stringContainsEmoji:(NSString *)string {
    __block BOOL returnValue = NO;
    [string enumerateSubstringsInRange:NSMakeRange(0, [string length]) options:NSStringEnumerationByComposedCharacterSequences usingBlock:
     ^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
         
         const unichar hs = [substring characterAtIndex:0];
         // surrogate pair
         if (0xd800 <= hs && hs <= 0xdbff) {
             if (substring.length > 1) {
                 const unichar ls = [substring characterAtIndex:1];
                 const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
                 if (0x1d000 <= uc && uc <= 0x1f77f) {
                     returnValue = YES;
                 }
             }
         } else if (substring.length > 1) {
             const unichar ls = [substring characterAtIndex:1];
             if (ls == 0x20e3) {
                 returnValue = YES;
             }
         } else {
             // non surrogate
             if (0x2100 <= hs && hs <= 0x27ff) {
                 returnValue = YES;
             } else if (0x2B05 <= hs && hs <= 0x2b07) {
                 returnValue = YES;
             } else if (0x2934 <= hs && hs <= 0x2935) {
                 returnValue = YES;
             } else if (0x3297 <= hs && hs <= 0x3299) {
                 returnValue = YES;
             } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50) {
                 returnValue = YES;
             }
         }
     }];
    
    return returnValue;
}

TextView 中禁止切换Emoj键盘

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
{
    if ([[[textView textInputMode] primaryLanguage] isEqualToString:@"emoji"] || ![[textView textInputMode] primaryLanguage])
    {
        DLog(@"Disable Emoji Keyboard");
        [UIAlertView showWithTitle:@"Oops" message:@"Please do not input Emoji." cancelButtonTitle:@"OK" otherButtonTitles:nil tapBlock:nil];
        return NO;
    }
    return YES;
}
2018-07-05 10:20:00 weixin_34274029 阅读数 28


//判断是否有emoji
-(BOOL)stringContainsEmoji:(NSString *)string
{
    __block BOOL returnValue = NO;
    
    [string enumerateSubstringsInRange:NSMakeRange(0, [string length])
                               options:NSStringEnumerationByComposedCharacterSequences
                            usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
                                const unichar high = [substring characterAtIndex: 0];
                                
                                // Surrogate pair (U+1D000-1F9FF)
                                if (0xD800 <= high && high <= 0xDBFF) {
                                    const unichar low = [substring characterAtIndex: 1];
                                    const int codepoint = ((high - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
                                    
                                    if (0x1D000 <= codepoint && codepoint <= 0x1F9FF){
                                        returnValue = YES;
                                    }
                                    
                                    // Not surrogate pair (U+2100-27BF)
                                } else {
                                    if (0x2100 <= high && high <= 0x27BF){
                                        returnValue = YES;
                                    }
                                }
                            }];
    
    return returnValue;
}



2017-05-15 11:15:00 weixin_33860722 阅读数 15

文字(UI或分享时的标题(描述))展示给用户的时候,可能需要过滤掉html标签,有的开发团队可能把过滤操作放在后端处理,其实放在前端做相对来说比较合理(灵活性)。

  • 那么怎样才能高效有效的过滤这些标签呢?首先想到的就是使用正则……我们我可以写一个NSString->Category
#pragma mark - ============== 正则去除HTML标签 ==============
+ (NSString *)getNormalStringFilterHTMLString:(NSString *)htmlStr{
    NSString *normalStr = htmlStr.copy;
    //判断字符串是否有效
    if (!normalStr || normalStr.length == 0 || [normalStr isEqual:[NSNull null]]) return nil;
    
    //过滤正常标签
    NSRegularExpression *regularExpression=[NSRegularExpression regularExpressionWithPattern:@"<[^>]*>" options:NSRegularExpressionCaseInsensitive error:nil];
    normalStr = [regularExpression stringByReplacingMatchesInString:normalStr options:NSMatchingReportProgress range:NSMakeRange(0, normalStr.length) withTemplate:@""];
    
    //过滤占位符
    NSRegularExpression *plExpression=[NSRegularExpression regularExpressionWithPattern:@"&[^;]+;" options:NSRegularExpressionCaseInsensitive error:nil];
    normalStr = [plExpression stringByReplacingMatchesInString:normalStr options:NSMatchingReportProgress range:NSMakeRange(0, normalStr.length) withTemplate:@""];
    
    //过滤空格
    NSRegularExpression *spaceExpression=[NSRegularExpression regularExpressionWithPattern:@"^\\s*|\\s*$" options:NSRegularExpressionCaseInsensitive error:nil];
    normalStr = [spaceExpression stringByReplacingMatchesInString:normalStr options:NSMatchingReportProgress range:NSMakeRange(0, normalStr.length) withTemplate:@""];

    return normalStr;
}

Perfect over~~

2015-06-08 14:38:48 yxycowboy 阅读数 1135
iOS输入框过滤emoji表情
//
//  ViewController.m
//  test
//
//  Created by 郭宇 on 13-11-15.
//  Copyright (c) 2013年 郭 宇. All rights reserved.
//
 
#import "ViewController.h"
 
@implementation ViewController
{
    IBOutlet UITextView *textinput;
}
 
- (void)viewDidLoad
{
    [super viewDidLoad];
    [textinput setDelegate:self];
}
 
- (void)textViewDidChange:(UITextView *)textView
{
    NSRange textRange = [textView selectedRange];
    [textView setText:[self disable_emoji:[textView text]]];
    [textView setSelectedRange:textRange];
}
 
- (NSString *)disable_emoji:(NSString *)text
{
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]" options:NSRegularExpressionCaseInsensitive error:nil];
    NSString *modifiedString = [regex stringByReplacingMatchesInString:text
                                                               options:0
                                                                 range:NSMakeRange(0, [text length])
                                                          withTemplate:@""];
    return modifiedString;
}
 
@end
转载自code4app:点击打开链接

iOS 过滤Emoji表情

阅读数 13

iOS过滤数据字典

阅读数 1654

ios过滤emoji表情

阅读数 327

iOS 搜索过滤

阅读数 155

iOS RAC - 过滤

阅读数 27

没有更多推荐了,返回首页