怎么做类似淘宝网站吗,网络服务商名称,网址导航下载到桌面,外贸营销型网站建设公司1. 关键词2. strutil.h3. strutil.cpp4. 测试代码5. 运行结果6. 源码地址
1. 关键词
关键词#xff1a;
C 字符串处理 分割字符串 连接字符串 跨平台
应用场景#xff1a;
有些重要信息需要保密#xff0c;比如手机号、邮箱等#xff0c;如何在不影响用户阅读的情况下…1. 关键词2. strutil.h3. strutil.cpp4. 测试代码5. 运行结果6. 源码地址
1. 关键词
关键词
C 字符串处理 分割字符串 连接字符串 跨平台
应用场景
有些重要信息需要保密比如手机号、邮箱等如何在不影响用户阅读的情况下将这些信息脱敏处理以保障用户的隐私安全。
2. strutil.h
#pragma once#include stringnamespace cutl
{/*** brief Desensitizing a string by replacing some characters with *.** param str the string to be desensitized.* return std::string the desensitized string.*/std::string desensitizing(const std::string str);
} // namespace cutl3. strutil.cpp
#include cctype
#include algorithm
#include strutil.hnamespace cutl
{// 字符串脱敏处理std::string desensitizing(const std::string str){std::string result;// 只打印前1/4和后1/4的内容中间用*表示if (str.empty()){result ;}else if (str.length() 1){result *;}else if (str.length() 2){result str.substr(0, 1) std::string(str.length() - 1, *);}else if (str.length() 6){result str.substr(0, 2) std::string(str.length() - 2, *);}else if (str.length() 10){result str.substr(0, 2) std::string(str.length() - 4, *) str.substr(str.length() - 2, 2);}else if (str.length() 16){// 长度控制在最长12位中间×不超过6auto startCount (str.length() - 6) 6 ? 6 : (str.length() - 6);result str.substr(0, 3) std::string(startCount, *) str.substr(str.length() - 3, 3);}else{// 长度控制在最长12位result str.substr(0, 4) std::string(4, *) str.substr(str.length() - 4, 4);}return result;}
} // namespace cutl4. 测试代码
#include common.hpp
#include strutil.hvoid TestDesensitizing()
{PrintSubTitle(desensitizing);std::string password 2515774;std::cout password: cutl::desensitizing(password) std::endl;std::string phone 18500425678;std::cout phone: cutl::desensitizing(phone) std::endl;
}5. 运行结果
-------------------------------------------desensitizing--------------------------------------------
password: 25***74
phone: 185*****6786. 源码地址
更多详细代码请查看本人写的C 通用工具库: common_util, 本项目已开源代码简洁且有详细的文档和Demo。