服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

解决中文问题的几个常用的函数(2)


  解决中文问题的几个常用的函数(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中直接用文本编辑器直接修改。

扫描关注微信公众号