public class testString
{
public static void main(String[] args)
{
String testStr = " d d ";
char[] c = new char[5];
int j=0;
for(int i=0; i < testStr.length(); i++)
{
if(!(testStr.charAt(i) == ' '))
{
c[j] = testStr.charAt(i);
j++;
}
}
testStr = new String(c);
System.out.println(testStr);
}
}
{
public static void main(String[] args)
{
String testStr = " d d ";
char[] c = new char[5];
int j=0;
for(int i=0; i < testStr.length(); i++)
{
if(!(testStr.charAt(i) == ' '))
{
c[j] = testStr.charAt(i);
j++;
}
}
testStr = new String(c);
System.out.println(testStr);
}
}
解决方案 »
- hibernate执行多对多关联查询时,关联表数据被删除
- 两个很奇怪的错误。求解释
- 几个面试笔试题
- tomcat 配置 J AVA虚拟机分配内存问题
- 网站访问量1200IP/天,该用什么数据库?我现在用的是ACCESS数据库,这个访问量是不是该换成SQL数据库?
- 高手们 帮小第一个忙好么 感激不尽 就剩10分了
- 小问题:立即揭帖!
- 请帮忙看一下下面的对数据库的操作有没有错误?
- 怎么 C:\>jar cf my.jar * 会出现'jar' 不是内部或外部命令,也不是可运行的程序
- 请问,哪儿有VisiBroker for Java下载?
- response.setHeader("Expires:","0"); 是什么意思,有何作用?
- 为什么在jb7中建立的web_app,有的jsp能编译而有些不能编译,请教
Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar. String replaceAll(String regex, String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement. String replaceFirst(String regex, String replacement)
Replaces the first substring of this string that matches the given regular expression with the given replacement.
============================
public static String stringReplace(String __strSourceString, String __strOldString, String __strNewString)
{
String strReturnString = __strSourceString;
int nLength = 0;
if(__strOldString != null)
{
nLength = __strOldString.length();
}
if(strReturnString != null && strReturnString.length() > nLength)
{
int max = 0;
String strAllStep = "";
for(int i = 0; i < __strSourceString.length(); i++)
{
max = i + __strOldString.length() > __strSourceString.length()? __strSourceString.length():i + nLength;
String strOneStep = __strSourceString.substring(i, max);
if(!strOneStep.equals(__strOldString))
{
strAllStep += strOneStep.substring(0,1);
}else{
strAllStep += __strNewString;
i += nLength -1 ;
}
}
strReturnString = strAllStep;
}
return strReturnString;
}
==============
下面的也可以,不过有些局限性,不过解决你的问题应该可以
=================
String strIn1 = "hello. Today \"I am \"";
System.out.println(strIn1);
StringTokenizer oToken1 = new StringTokenizer(strIn1);
String strResult = "";
while(oToken1.hasMoreElements())
{
strResult += oToken1.nextToken();
}
strResult是结果