项目中遇到的问题,要记录下来,以便以后回顾。
1、截取一个字符串中所有{}内的内容,采用正则表达式方式。
例: str=我爱中国{123}天安门,天安门前{456}太阳升起!
stringP1='\"[^"{}}{1,}"; pattern pattern1=pattern.com pile (P1; matcherm=pattern1.matcher(str ); while(m.find () ) system.out.println (m.group ) ); 结果: {123} {456}
2、剪切单引号内容。 子串方式
str={src='zdw ',tgt='zlb ',rel='brother'}
//srcString Src=str2.split (,() )0).substring (str2. split ),) )0).indexof )、()、(1)、)和trim )。 stringsrc=src.substring(0,Src.length ) (-1 ); //tgtString Tgt=str2.split (,() )1).substring (str2. split ),)0).indexof ),(),((1) ),(trim )。 stringTGT=TGT.substring(0,Tgt.length ) (-1 ); //relString Rel=str2.split (,() ).substring (str2. split ),) )0).indexof ),(),),),) trim ) system.out.println(src;
system.out.println(TGT;
system.out.println(rel;
结果: zdw zlb brother