本文介绍了替换“^” char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用字符串替换^字符,使用:

  String text = text.replaceAll ^,put this text); 

如果文字为以下值:

 x ^我的字符串
 this thisx ^ my string

这只会在 ^ 字符的情况下发生



只要使用非正则表达式版本而不是 String.replaceAll()

 code> text = text.replace(^,put this text); 


I'm trying to replace the "^" character on a String using:

String text = text.replaceAll("^", "put this text");

If text as the following value:

"x^my string"

The resulting String is:

"put this textx^my string"

This only happens in case of the ^ character

Why is this?

解决方案

Just use the non-regex version String.replace() instead of String.replaceAll():

text = text.replace("^", "put this text");

这篇关于替换“^” char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 14:22