删除字符串中的换行符号的几种方式:
1.使用String的replaceAll()方法;
2.使用google guava的CharMatcher.breakingWhitespace();
3.使用Apache Commons包的StringUtils.chomp();方法;
pom依赖
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.1-jre</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
package com.example.demo;
import com.google.common.base.CharMatcher;
import org.apache.commons.lang3.StringUtils;
* @author Walker
* @since 1.0 2018-10-09
public class RemoveCarriageTest {
public static void main(String[] args) {
//使用replaceAll
String text = "Our line rackets \rthe encouraged symmetry.\n";
String result = text.replaceAll("\n", "").replaceAll("\r", "");
System.out.println(result);
String randomSentence = "The backed valley manufactures \r"
+ "a politician above \n" + "a scratched body.";
//google guava
result = CharMatcher.breakingWhitespace().removeFrom(randomSentence);
System.out.println(result);
//apache commons
String randomSentence2 = "The pocket reflects "
+ "over an intimate. \r";
result = StringUtils.chomp(randomSentence2);
System.out.println(result);
Our line rackets the encouraged symmetry.
Thebackedvalleymanufacturesapoliticianaboveascratchedbody.
The pocket reflects over an intimate.
删除字符串中的换行符号的几种方式:1.使用String的replaceAll()方法;2.使用google guava的CharMatcher.breakingWhitespace();3.使用Apache Commons包的StringUtils.chomp();方法;pom依赖&lt;dependency&gt; &lt;groupId&gt;com.google.guava&lt...
1、空字符串检查public static boolean isEmpty(String str);
public static boolean isNotEmpty(String str);上面两个方法是判断字符串是否为”“或者null。public static boolean isBlank(String str);
public static boolean isNotBlank(Strin
Algorithm实现
#####算法背景:
由于公司内游戏对国际化支持不够友好,其中文字断行方面并未够完美,仅仅支持空格以及换行符,并未考虑中文全角标点符号,英语以及数字混合等复杂情况,本算法正是为了完美解决中文
英语以及标点符号
数学表达式的自动换行。
#####算法综述:
此算法基于
由于英语换行是有明确规则,Unicode
Breaking
Algorithm上明确定义了所有英语换行规则,例如:
1.英语字母与空格一起时运行空格后面换行
2.当英语字母处于破折号-前面时不允许换行,但允许在-后面换行,同时如果-后面是数字的话则不允许换行。
3.当左括号(后面接着英语字母或者数字时不允许换行,同时当英语字母或者数字紧挨着右括号)时不允许换行。
因此Unicode
Breaking
Algorithm先把所有字符归类,
String result = "";
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(result);
result = m.replaceAll("");
CSDN-Ada助手:
jmeter-connection refused timeout
知_信_行:
HTML-视频高度自适应解决方法
流浪者°:
Spring-Core-Container @Autowired源码探讨
zhaohongxu11:
MySQL-出现Waiting for table metadata lock的原因方法
CUG_ZG: