sell- 获取邮箱的后缀
1.
public static void main(String[] args) {
System.out.println(getEmailSuffix("jim_chen28270@163.com")); // 163.com
System.out.println(getEmailSuffix("@qq.com")); //qq.com
}
private static String getEmailSuffix(String email) {
email = defaultIfBlank(email,"").trim();
if (!email.isEmpty()) {
int index = email.indexOf('@') + 1;
if (index < email.length()) {
return email.substring(index).toLowerCase();
}
}
return "";
}
public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr) {
return isBlank(str) ? defaultStr : str;
}
public static boolean isBlank(final CharSequence cs) {
int strLen;
if (cs == null || (strLen = cs.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}
}
2. 优化,封装到一个公用的字符串操作类中去
public static String getEmailSuffix(String email) {
email = MyStringUtils.defaultIfBlank(email,"").trim();
if (!email.isEmpty()) {
int index = email.indexOf('@') + 1;
if (index < email.length()) {
return email.substring(index).toLowerCase();
}
}
return "";
}
//自己封装的字符串操作类
class MyStringUtils {
public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr) {
return isBlank(str) ? defaultStr : str;
}
public static boolean isBlank(final CharSequence cs) {
int strLen;
if (cs == null || (strLen = cs.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}
public static boolean isNotBlank(final CharSequence cs) {
return !isBlank(cs);
}
public static String defaultString(Object obj) {
return obj == null ? "" : obj.toString();
}
}
sell- 获取邮箱的后缀的更多相关文章
- 爬虫获取邮箱,存入数据库,发送邮件java Mail
在网页上获取邮箱: package com.my.test; import java.io.BufferedReader; import java.io.InputStreamReader; impo ...
- 获取邮箱使用情况、以及最后一次logon时间
# 每天收发邮件数 # https://gallery.technet.microsoft.com/scriptcenter/Count-sent-and-recceived-f9c66cf7 # 获 ...
- Python tldextract模块准确获取域名和后缀
Python tldextract 模块 - 功能说明 tldextract准确地从URL的域名和子域名分离通用顶级域名或国家顶级域名. 例如,http://www.google.com,你只想取出连 ...
- Java获取文件的后缀名。
/** * 详细步骤 */ private static void test1() { //获取文件的原始名称 String originalFilename = "tim.g (1).jp ...
- C#获取图片的后缀名
最近在学习过程中遇到一个问题,就是如何获取图片的格式,对于一张知道全路径的照片,如果其路径包含后缀名的话,要取得后缀名,只需要一行代码即可: var ext = System.IO.Path.GetE ...
- FileUtils【获取SD卡根目录、读写文件、移动、复制、删除文件、获取文件名、后缀名操作类】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 封装了获取SD卡根目录路径.以及对文件读写.获取文件名等相关操作. 因为需要用到android.permission.READ_EX ...
- .net 获取邮箱邮件列表和内容
需求: 最近项目里遇到了个问题,对方没有提供直接获取数据源的api接口,而是通过邮件发数据的.这就需要接收邮件后解析邮件内容获得数据. 分析: 想在代码里实时获取邮件,可以通过邮件的几个协议来实现,常 ...
- novell.directory.ldap获取邮箱活动目录
在windows系统上可以使用下列方法来查找所有的员工邮箱和员工组: StringDictionary ReturnArray = new StringDictionary(); Dictionary ...
- php获取文件名和后缀名
php获取文件名 1 function retrieve($url) 2 { 3 preg_match('/\/([^\/]+\.[a-z]+)[^\/]*$/',$url,$match); 4 re ...
- JS 根据文件路径获取名字和后缀名
var fileName = this.from.doc.substring(this.from.doc.lastIndexOf('/')+1); //文件名 var extNam ...
随机推荐
- 【BZOJ】1901: Zju2112 Dynamic Rankings(区间第k小+树状数组套主席树)
http://www.lydsy.com/JudgeOnline/problem.php?id=1901 首先还是吐槽时间,我在zoj交无限tle啊!!!!!!!!我一直以为是程序错了啊啊啊啊啊啊. ...
- 使用Eclipse自带Web Service插件(Axis1.4)生成Web Service服务端/客户端
创建一个名字为math的Java web工程,并将WSDL文件拷入该工程中 将Axis所需的jar包拷贝至WebRoot\WEB-INF\lib目录下,这些jar包会自动导入math工程中 一,生成W ...
- VFS
VFS的作用:为文件系统提供通用的接口. 通用文件模型:common file model.特殊文件系统需要将它的物理结构转换成通用文件模型. common file model包括以下几个重要对象: ...
- HDU 5773 最长上升子序列
题意 给出一个序列 问它的最长严格上升子序列多长 这个序列中的0可以被替代为任何数 n的范围给出了1e5 所以平常的O(n*n)lis不能用了 在kuangbin的模板里有O(nlogn)的模板 套上 ...
- [IT学习]关于minidump
windows debug里面需要用到数据分析. 很重要的一个工具就是dump. 什么事minidump,就是windows在蓝屏或其他故障时,转存的内存数据.(我现在是这么理解的) Applicat ...
- [转自小兵的工具箱]C++ Builder 基础
1. C++ Builder 网上资源 C++ Builder 研究 http://www.ccrun.com/ C++ Builder 程序员 http://mybcb.diy.myri ...
- ①spirngMVC框架运行原理图
- 在serviceImpl里使用自身的方法
@Service("tbLeaveRegisterService")@Transactionalpublic class TbLeaveRegisterServiceImpl ex ...
- Bluetooth RFCOMM介绍
目录 1. 介绍 2. 服务概述 2.1 RS-232控制信号 2.2 Null Modem Emulation 2.3 多串口仿真 3. 服务接口描述 4. RFCOMM帧类型 5. RFCOMM帧 ...
- UISearchBar cover first cell of UITableView
1.相当重要的是 tableView.tableHeaderView = searchBar; 这一句一定要在 UIViewController viewDidLoad 的时候执行,否则就会出现 se ...