java初学者必读-经验总结(2)
8:字符串分割:
public int getCount(String str,String sign){//查找某一字符串中str,特定子串s的出现次数
if(str==null) return 0;
StringTokenizer s=new StringTokenizer(str,sign);
return s.countTokens();
}
public String[] getArray(String str,String sign){//按特定子串s为标记,将子串截成数组。
int count=getCount(str,sign);
int j=0;
String[] arr=new String[count];
for(int i=0;i<count;i++){
if(str.indexOf(sign)!=-1){
j =str.indexOf(sign);
arr[i]=str.substring(0,j);
str =str.substring(j+1);
}else{
arr[i]=str;
}
}
return arr;
}
9:jdk1.3没有字符串替换函数,(jdk1.4有)。
解决1.3中的个这个问题如下:
public String stringReplace(String sourceString, String toReplaceString, String replaceString)
{
String returnString = sourceString;
int stringLength = 0;
if(toReplaceString != null)
{
stringLength = toReplaceString.length();
}
if(returnString != null && returnString.length() > stringLength)
{
int max = 0;
String S4 = "";
for(int i = 0; i < sourceString.length(); i++)
{
max = i + toReplaceString.length() > sourceString.length()? sourceString.length():i + stringLength;
String S3 = sourceString.substring(i, max);
if(!S3.equals(toReplaceString))
{
S4 += S3.substring(0,1);
}else{
S4 += replaceString;
i += stringLength -1 ;
}
}
returnString = S4;
}
return returnString;
}
9:设置weblogic连接池:
pool的配置:
假设已配置服务:expserv
且数据库服务器机器名为:expserv
数据库sid:expservSID,用户名和密码都为:expserv
以weblogic7.0为例,首先启动服务
http://localhost:port/console
打开service\jdbc\connection pools
配置oraclePool如下:
Configuration:
Name: oraclePool
URL: jdbc:oracle:thin:@expserv:1521:expservSID
Driver Classname: oracle.jdbc.driver.OracleDriver
Properties(key=value): user=expserv
Targets:
Targets-Server:expserv
在weblogic7.0中除了数据库密码,其他的pool参数都可以在config.xml中直接用文本编辑器直接修改。
10:数字转货币大写(js)
function ChangeToBig(value)
{
var intFen,i;
var strArr,strCheck,strFen,strDW,strNum,strBig,strNow;
if(trim(value)=="") //数据为空时返回"零"
return "零";
if (isNaN(value)) //数据非法时提示,并返回空串
{
strErr = "数据"+value+"非法!"
alert(strErr);
return "";
}
strCheck = value+".";
strArr = strCheck.split(".");
strCheck = strArr[0];
if(strCheck.length>12) //数据大于等于一万亿时提示无法处理
{
strErr = "数据"+value+"过大,无法处理!"
alert(strErr);
return "";
}
try
{
i = 0;
strBig = "";
intFen = value*100; //转换为以分为单位的数值
strFen = intFen.toString();
strArr = strFen.split(".");
strFen = strArr[0];
intFen = strFen.length; //获取长度
strArr = strFen.split(""); //将各个数值分解到数组内
while(intFen!=0) //分解并转换
{
i = i+1;
switch(i) //选择单位
{
case 1:strDW = "分";break;
case 2:strDW = "角";break;
case 3:strDW = "元";break;
case 4:strDW = "拾";break;
case 5:strDW = "佰";break;
case 6:strDW = "仟";break;
case 7:strDW = "万";break;
case 8:strDW = "拾";break;
case 9:strDW = "佰";break;
case 10:strDW = "仟";break;
case 11:strDW = "亿";break;
case 12:strDW = "拾";break;
case 13:strDW = "佰";break;
case 14:strDW = "仟";break;
}
switch (strArr[intFen-1]) //选择数字
{
case "1":strNum = "壹";break;