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 ...
随机推荐
- CSS3选择器(一)之基本选择器
CSS的选择器,我想大家并不会陌生吧,因为天天在使用,但对于CSS3的选择器,要运用的灵活到位,我想对很多朋友还是一定的难度,特别是CSS3中的:nth选择器.那么从现在开始我们先丢开他们版本的区别, ...
- Hibernate使用MyExclipse10自动生成配置文件报错
使用MyExclipse10自动生成hibernate映射文件如下: 结果发现启动服务时报以下错误: 原因:因为hibernate换过项目地址,所以dtd文件的地址也换掉了.在hbm.xml文件里面把 ...
- SparkContext.setCheckpointDir()
class SparkContext extends Logging with ExecutorAllocationClient Main entry point for Spark function ...
- thinkphp模型没继承model报的错
Call to undefined method RoleModel::query() 错误位置 FILE: H:\www\tpsmarty\shop\Lib\Model\RoleModel.clas ...
- 基本Java数据类型
一.整型:java中的基本数据类型byte,占用1个字节,8位 取值范围:0000 0000 ~ 1111 1111 (-128 ~ 127) 为什么不是:0000 0000 ~ 1111 1 ...
- 【液晶模块系列基础视频】1.3.iM_TFT30模块简介
[液晶模块系列基础视频]1.3.iM_TFT30模块介绍 ============================== 技术论坛:http://www.eeschool.org 博客地址:http:/ ...
- Sql Server 常用方法、存储过程备用
常用方法 --字符串转换成数字 --CAST("1" AS int) --CONVERT(int,"1") --截取字符串 SUBSTRING(OccurreA ...
- mysql IN 比等价的OR写法效率更高
- How To Ask Questions The Smart Way
How To Ask Questions The Smart Way Eric Steven Raymond Thyrsus Enterprises <esr@thyrsus.com> R ...
- 【IOS笔记】View Programming Guide for iOS -1
原文:View Programming Guide for iOS View and Window Architecture Views and windows present your applic ...