添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

删除字符串中的换行符号的几种方式:
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依赖&amp;lt;dependency&amp;gt;	&amp;lt;groupId&amp;gt;com.google.guava&amp;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助手: 嗨~好久未见你更新博文了,我们现在上线了AI创作助手哦~可为你的创作提供智能化帮助,快来试试吧~https://editor.csdn.net/md/?not_checkout=1&utm_source=blog_comment_recall,在编辑器页面右侧哦~~限免!! 同时我们为您准备了一份回归奖励,快来看看吧https://activity.csdn.net/creatActivity?id=10430&utm_source=blog_comment_recall jmeter-connection refused timeout 知_信_行: 我也遇到这种情况了,到现在也没解决 HTML-视频高度自适应解决方法 流浪者°: width: 100% height:100% object-fit: fill;就可以了 Spring-Core-Container @Autowired源码探讨 zhaohongxu11: 感谢,解决了我的疑惑 MySQL-出现Waiting for table metadata lock的原因方法 CUG_ZG: 搬运工这么嚣张了, 都不写出处了?