Str 里面有中文分号和英文分号吗?
解决方案 »
- java初学者提问,com.microsoft.sqlserver.jdbc.SQLServerException: 没有为参数号 6 设置值,只是什么异常?
- JEditorPane的setPage()方法中能用相当路径吗?能用的话,怎么用?
- socket传送多个文件
- 想了解java开发语音方面的知识
- 如何调整jcreator的编程风格?
- 用java做过网络游戏的请进!!!!
- 有人在solaris 下面装过iplanet web server 吗???
- ---关于在网页上显示图片的问题
- 为什么》
- 急!!!excel文件作为数据源,java能连接这样的数据源吗?
- 请问,怎么才能直接调用outlook中的“新邮件”窗口,来发送邮件。如何直接将对方邮件地址传入。(比如网页上提供的该公司email发送)。
- 请教大家一道题目
StringTokenizer st = new StringTokenizer("2003-12-25;0.001mg/cm;通道a;0.002mg/cm;通道b;……;0.00nmg/cm;通道n;", ";");
while (st.hasMoreTokens()) {
println(st.nextToken());
}
:(希望高手能改进import java.util.regex.*;
public class TestStr {
static Pattern p;
static String str="2003-12-25;0.001mg/cm;通道a;0.002mg/cm;通道b;……;0.00nmg/cm;通道n;\r";
static String[] strTest=str.split(";");
public TestStr() {
}
static String getTime(){
// p=Pattern.compile("^[\\d]{4}\\-[\\d]{2}\\-[\\d]{2}$");
return strTest[0];
}
static String getTag(int index){
String strTemp="^通道[A-z]{1}$";
int j=0;
if (index>strTest.length)
return "输入非法";
for(int i=0;i<strTest.length;i++){
if (Pattern.matches(strTemp,strTest[i]))
{ j++;
if (j == index)
return strTest[i];
}
continue;
}
return "没有你要找的";
}
static String getData(int index){
String strTemp="^0.00"+index+"mg/cm$";
for(int i=0;i<strTest.length;i++){
if (Pattern.matches(strTemp,strTest[i]))
return strTest[i];
continue;
}
return "没有你要找的"; } public static void main(String[] args) {
System.out.println(getData(2));
}}
String tmp="info-info2-的得-hoho";如果你在tmp里设置了分隔符,例如我这里的是'-'作为分歌符的那么你可以用如下方法:
String[] str=tmp.split("-");
会获得如下结果:
str[0]="info";
str[1]="info2";
str[2]="的得";
str[3]="hoho";