首页 > 编程语言 >C#.NET FRAMEWORK .NET CORE .NET6 .NET8 判断是否Emoji

C#.NET FRAMEWORK .NET CORE .NET6 .NET8 判断是否Emoji

时间:2024-07-03 10:55:53浏览次数:1  
标签:CORE codePoint string C# System using NET Emoji

C#.NET FRAMEWORK .NET CORE .NET6 .NET8 判断是否Emoji

 

工具类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleThreadTimer
{
    public class EmojiUtil
    {
        /// <summary>
        /// 判断String中是否包含Emoji
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static bool ContainsEmoji(string source)
        {
            if (string.IsNullOrWhiteSpace(source))
            {
                return false;
            }
            int len = source.Length;
            foreach (char item in source)
            {
                if (!IsEmojiCharacter(item))
                {

                    //如果不能匹配,则该字符是Emoji表情
                    return true;
                }
            }
            return false;
        }


        /// <summary>
        ///根据char判断是否是Emoji
        /// </summary>
        /// <param name="codePoint"></param>
        /// <returns></returns>
        private static bool IsEmojiCharacter(char codePoint)
        {
            return (codePoint == 0x0) || (codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD)
                             || ((codePoint >= 0x20) && (codePoint <= 0xD7FF))
                             || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD))
                             || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF));
        }

        public static string RemoveEmoji(string source)
        {
            if (string.IsNullOrWhiteSpace(source))
            {
                return "1";
            }
            StringBuilder sc = new StringBuilder();
            int len = source.Length;
            foreach (char item in source)
            {
                if (!IsEmojiCharacter(item))
                {
                    continue; // IsEmojiCharacter 等于false,是Emoji
                }
                sc.Append(item);
            }
            string finalStr= sc.ToString();
            if (string.IsNullOrWhiteSpace(finalStr))
            {
                return "1";
            }
            return finalStr;
        }
    }
}

 

使用:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleThreadTimer
{
    class Program
    {
        static void Main(string[] args)
        {
            string testString1 = "条码支付-pos-蜜雪冷饮-    新贝特中国汉堡

标签:CORE,codePoint,string,C#,System,using,NET,Emoji
From: https://www.cnblogs.com/runliuv/p/18281158

相关文章

  • 2024UIUCTF - OSINT - Night
    2024UIUCTF-OSINT-Night题目描述Author:CBCicadaThatwasquiteaprettynightview,canyoufindwhereItookit?Flagformat:uiuctf{streetname,cityname}Example:uiuctf{EastGreenStreet,Champaign}Somewordsareblurredouttomakethechallengeh......
  • WSL2安装cuda
    Windows下的WSL2是适用于Linux的Windows子系统体系结构的一个新版本,它支持适用于Linux的Windows子系统在Windows上运行ELF64Linux二进制文件。它的主要目标是提高文件系统性能,以及添加完全的系统调用兼容性。使用WSL2可以很方便地调试程序,在WSL2中部署cuda环境更......
  • Docker 使用 buildx 构建多种系统架构支持的镜像
    在Docker19.03+版本中可以使用 dockerbuildxbuild 命令使用 BuildKit 构建镜像。该命令支持 --platform 参数可以同时构建支持多种系统架构的Docker镜像,大大简化了构建步骤。安装模拟器DockerforLinux不支持构建 arm 架构镜像,我们可以运行一个新的容器让其支......
  • 搭建工程之一 eclipse 中基于 maven 的 webapp工程能基于tomcat运行
    一、背景  作为开发人员,开发的web(运行在tomcat容器中)希望能够在本地开发工具(eclipse)中运行调试,加快开发测试进度。二、操作步骤1、创建maven工程 在eclipse上右键,选择"New"---"Other"---"Maven"----"MavenProject" 勾选上“Createasimpleproject”......
  • 丝滑解决ImportError: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_
    基础环境:MacOSm1、python=3.9前情提要:在Anaconda终端运行代码的时候,显示报错:importError:/usr/lib/x86_64-linux-gnu/libstdc++.so.6:version`GLIBCXX_3.4.29'notfound1问题分析:根据提示是/usr/lib/x86_64-linux-gnu/路径下的libstdc++.so.6缺少版本GLIBCXX_3.4.29解......
  • cmsis and hal
    CMSIS(CortexMicrocontrollerSoftwareInterfaceStandard)andHAL(HardwareAbstractionLayer)arebothsoftwarelayersusedinthedevelopmentofembeddedsystems,particularlyformicrocontrollers.Theyservedifferentpurposesandareoftenusedtoget......
  • VSCode + Qt + QMake 开发编译环境搭建
    鉴于Qt官方IDE太过难用,VSCode+各种插件功能强大,遂采用VSCode来写Qt项目;本博客在Windows平台进行指导操作,Mac、Linux平台配置方式类似,学习其本质就可。前置准备VSCode,最新版本即可本地Qt环境,版本随意,本文主要针对较老版本使用Qmake构建系统的项目环境变量Qt环境变......
  • opensearch-2.11.1安装
    一、opensearch简介官网:https://www.opensearch.org/下载:https://www.opensearch.org/versions/opensearch-2-11-1.html1.1OpenSearch的基本概念和特点OpenSearch是由数据存储和搜索引擎(OpenSearch)、可视化和用户界面(OpenSearchDashboards)以及服务器端数据收集器(Da......
  • JDK、Tomcat、Maven配置
    一、JDK安装及配置1.下载地址:https://www.oracle.com/java/technologies/downloads/2.下载后直接本地安装,选择路径默认即可,类似如下路径:C:/ProgramFiles/Java/jdk_1.8.0_3013.配置环境变量路径:程序->计算机->右键->属性->高级系统设置->高级->环境变量(以win10为例)4.配置......
  • linux安装telnet服务(Centos7.9环境)
    使用telnet临时替代ssh安装配置接上一篇OpenssH升级至9.8P1教程发出后有不少朋友反馈在升级过程中服务器连接断开无法远程,对租用云服务器的朋友们不是太友好,后续只能联系云厂商或者通过购买云服务器账号后台登陆操作浪费时间,现在我们可以采用安装telnet服务临时替代ssh远程登......