从字符串中分离出制定的部分
一个字符串中必定有“@@@”部分 要提取出他前面的部分转化成int 提取后面的部分赋给一个String类型变量!例如有String str="123"+"@@@"+"hello?";
提取之后 int ID = 123;
String str1="hello?";
大家给段代码吧 谢了
搜索更多相关的解决方案:
字符
----------------解决方案--------------------------------------------------------
用正则表达式
----------------解决方案--------------------------------------------------------
我刚才正在看! start(),end()方法是怎么用的?
import java.util.regex.*;
public class test {
public test() {
}
public static void main(String[] args){
String str="123"+"@@@"+"hello?";
Pattern p=Pattern.compile("@@@");
Matcher m=p.matcher(str);
//String s1=m.replaceAll("YES");
//System.out.println(s1);
int a=0;
a=m.start();
System.out.println(a);
}
}//提示java.lang.IllegalStateException 应该是没有找到匹配的!
???
千里 start() 怎么用的?
----------------解决方案--------------------------------------------------------
java 刚考完 扔了几天了 呵呵...写个简单点的罢 看看能满足你的意思不 写完别忘了回水区灌水哦
程序代码:
import java.util.*;
public class MM{
public static void main(String args[])
{
String str=\"123\"+\"@@@\"+\"hello?\";
StringTokenizer fenxi=new StringTokenizer(str,\"@@@\");
try
{int ID=Integer.parseInt(fenxi.nextToken());
System.out.println(\"ID=\"+ID);}
catch(Exception e) {}
String str1=fenxi.nextToken();
System.out.println(\"str1=\"+str1);
}
}
----------------解决方案--------------------------------------------------------
int ID=Integer.parseInt(str.substring(0,str.indexOf("@@@")));
String str1=str.substring(str.lastIndexOf("@@@")+3,str.length());
----------------解决方案--------------------------------------------------------
谢过楼上的 楼楼上的
import java.util.regex.*;
public class test {
public test() {
}
public static void main(String[] args){
String str="1212123@@@hello?";
String[] s=str.split("@@@");
System.out.println(s[0]);
System.out.println(s[1]);
}
}
这样也可以了
多谢了
----------------解决方案--------------------------------------------------------
以下是引用游乐园在2007-1-4 16:46:58的发言:
写完别忘了回水区灌水哦
收到! 看完去~
----------------解决方案--------------------------------------------------------
以下是引用海狂在2007-1-4 16:59:05的发言:
谢过楼上的 楼楼上的
import java.util.regex.*;
public class test {
public test() {
}
public static void main(String[] args){
String str="1212123@@@hello?";
String[] s=str.split("@@@");
System.out.println(s[0]);
System.out.println(s[1]);
}
}
这样也可以了
多谢了
谢过楼上的 楼楼上的
import java.util.regex.*;
public class test {
public test() {
}
public static void main(String[] args){
String str="1212123@@@hello?";
String[] s=str.split("@@@");
System.out.println(s[0]);
System.out.println(s[1]);
}
}
这样也可以了
多谢了
恩,方法很多,能实现就可以
----------------解决方案--------------------------------------------------------