java 删除字符串中的特定字符
- /**
- * Delete any character in a given String.
- * @param inString the original String
- * @param charsToDelete a set of characters to delete.
- * E.g. "az\n" will delete 'a's, 'z's and new lines.
- * @return the resulting String
- */
- public static String deleteAny(String inString, String charsToDelete) {
- if (!hasLength(inString) || !hasLength(charsToDelete)) {
- return inString;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < inString.length(); i++) {
- char c = inString.charAt(i);
- if (charsToDelete.indexOf(c) == -1) {
- sb.append(c);
- }
- }
- return sb.toString();
- }
- /**
- * Check that the given String is neither {@code null} nor of length 0.
- * Note: Will return {@code true} for a String that purely consists of whitespace.
- * @param str the String to check (may be {@code null})
- * @return {@code true} if the String is not null and has length
- * @see #hasLength(CharSequence)
- */
- public static boolean hasLength(String str) {
- return hasLength((CharSequence) str);
- }
- /**
- * Check that the given CharSequence is neither {@code null} nor of length 0.
- * Note: Will return {@code true} for a CharSequence that purely consists of whitespace.
- * <p><pre class="code">
- * StringUtils.hasLength(null) = false
- * StringUtils.hasLength("") = false
- * StringUtils.hasLength(" ") = true
- * StringUtils.hasLength("Hello") = true
- * </pre>
- * @param str the CharSequence to check (may be {@code null})
- * @return {@code true} if the CharSequence is not null and has length
- * @see #hasText(String)
- */
- public static boolean hasLength(CharSequence str) {
- return (str != null && str.length() > 0);
- }
java 删除字符串中的特定字符的更多相关文章
- Java-Runoob-高级教程-实例-字符串:03. Java 实例 - 删除字符串中的一个字符
ylbtech-Java-Runoob-高级教程-实例-字符串:03. Java 实例 - 删除字符串中的一个字符 1.返回顶部 1. Java 实例 - 删除字符串中的一个字符 Java 实例 以 ...
- 1231: 删除字符串中指定的字符(Java)
WUSTOJ 1231: 删除字符串中指定的字符 题目 原题链接 Description 明天就要英语考试了,小明明正在挑灯夜战背单词.小明明发现单词很难背,背一个忘一个.经过仔细研究,小明明发现单词 ...
- 三种java 去掉字符串中的重复字符函数
三种java 去掉字符串中的重复字符函数 public static void main(string[] args) { system.out.println(removerepeatedchar( ...
- jst通用删除数组中重复的值和删除字符串中重复的字符
以下内容属于个人原创,转载请注明出处,非常感谢! 删除数组中重复的值或者删除字符串重复的字符,是我们前端开发人员碰到很多这样的场景.还有求职者在被面试时也会碰到这样的问题!比如:问删除字符串重复的字符 ...
- Java 求字符串中出现频率最高字符
前段时间接触的这个题目,大体理解了,还有些小地方仍待进一步品味,暂且记下. import java.util.ArrayList; import java.util.Arrays; import ja ...
- 【自制工具类】Java删除字符串中的元素
这几天做项目需要把多个item的id存储到一个字符串中,保存进数据库.保存倒是简单,只需要判断之前是否为空,如果空就直接添加,非空则拼接个"," 所以这个字符串的数据结构是这样的 ...
- 使用Java判断字符串中的中文字符数量
Java判断一个字符串str中中文的个数,经过总结,有以下几种方法(全部经过验证),可根据其原理判断在何种情况下使用哪个方法: 1. char[] c = str.toCharArray(); for ...
- java 删除字符串中的反斜杠\
Java中有时候会打印出来会含有反斜杠(\)的字符串,我们需要删除时,可以使用 replace() 或 replaceAll() 但是要注意的是replaceAll()里面用的是正则表达式,所以一个斜 ...
- C语言删除字符串中重复的字符
#include <stdio.h> #include <string.h> #define NR(x) sizeof(x)/sizeof(x[0]) int Del_char ...
随机推荐
- PHP curl 采集内容之规则 1
<?phpheader("Content-type:text/html; charset=utf-8");$pattern = '/xxx(.*)yyyy/isU'; //i ...
- Razor与ASPX语法比较
- 简易ORM(基于注解)
这是从我们现有项目做的一定的改进准备做成IDE插件 类似getter和setter的生成 1.定义实体类 通过注解说明其表名和字段名(SOURCE类型的注解 不需要运行时使用)@TableName(& ...
- (转载)EhLib 在 Delphi 7 下的安装方法
EhLib 在 Delphi 7 下的安装方法 1.将 EhLib 解压到一个目录,如:E:\VCL\EhLib: 2.将 EhLib 安装目录下 Common 目录.DataService 目录下的 ...
- Django web 开发指南 no such table:
在学习django web开发指南时,发布新博客点击save后会有error提示:no such table balabalabala... 百度了一下说重新运行manage.py syncdb 就可 ...
- python 输出小数控制
一.要求较小的精度 将精度高的浮点数转换成精度低的浮点数. 1.round()内置方法round()不是简单的四舍五入的处理方式. >>> round(2.5) 2 >> ...
- Length of Last Word | Leetcode
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the l ...
- MYSQL数据库备份与恢复【转】
mysqldump -h主机名 -P端口 -u用户名 -p密码 (–database) 数据库名 > 文件名.sql 在window上需要通过CMD进入mysql安装目录下的bin目录下执行 ...
- centos系统使用技巧
===============================网络配置===============================1 eth0 接口配置:/etc/sysconfig/network ...
- Eclipse里初次使用Maven注意问题
在Eclipse里初次使用Maven,右键project->add dependency, 发现search不管用,这时候需要按照以下步骤操作: Goto "Preferences - ...