---
title: "String的常用操作方法2"
author: "primarykeylw"
date: "2012-07-05T09:52:16Z"
tags: ["String"]
categories: ["编程语言"]
slug: "string-2"
draft: false
lastmod: "2012-07-05T09:52:16Z"
id: 1577176
url: "https://primarykeylw.iteye.com/blog/1577176"
---

1.可对HQL语句查询时候加的%处理,去除%后的字符串. \[code="java"] /\** * * @param arg0 获取页面人工输入的查询条件 * @return 去除%后的字符串 \*/ public static String removedPercent(String arg0) { String result = ""; if (arg0 != null && arg0.length() &gt; 0) { for (int i = 0; i &lt; arg0.length(); i++) { char ch = arg0.charAt(i); if (ch != '%') result += ch; } } if(result.trim().length()==0) return "!{}$@#$%^&\*()!"; return result.trim(); }\[/code] 2.可针对fck或者备注content的换行处理 \[code="java"]//字符转换换行和空格 public static String replaceBR(String args){ if(args!=null&&args.trim().length()&gt;0){ return args.replaceAll("\\r\\n", "  
").replaceAll(" ", " "); } return ""; }\[/code]