0
解析網頁後,我發現這條線從線搜索字符串
「JANATAMF 7.30 -0.20 -2.67%80.00 1STBSRS -3.60 -4.31%12.90 1STPRIMFMF -0.80 -5.84%40.60 6THICB -2.50 -5.80 %8THICB 50.00 -1.30 -2.53%9.90 ABB1STMF 0.30 3.13%188.00 ACI -5.90 -3.04%82.70 ACIFORMULA 0.50 0.61%」
現在我想找到任何輸入,例如 對應的整數值,如果我輸入的輸入JANATAMF它將單獨打印7.30 -0.20 -2.67%
我已經寫了一個代碼,但它並不好看..
public void stringfinder(String linktext,String input) throws NumberFormatException
{
try
{
if(linktext!=null)
{
String finalstr=linktext;
//System.out.print(finalstr);
int inplen=input.length();
if(finalstr.contains(input)) //CHECK THE USER INPUT IS IN STRING OR NOT WHICH RETURN BOOLEAN
{
//System.out.println("found");
int index=finalstr.indexOf(input); //FIND THE INDEX OR STARTING POINT OF THE STRING
//System.out.print(index);
int stpr=index+inplen+1; //AS WE VE TO PRINT THE NEXT STRING FROM THE INPUT STRING
//WE ADD THE STARTING POINT OF THE INPUT STRING AND THE LENGTH
//OF THE INPUT STRING
//int first=0;
int i=0;
String x="" ;
String ary[]=new String[10];
while(finalstr.charAt(stpr)!=' ') //PRINT UNTIL FIND A GAP
{
//System.out.print(finalstr.charAt(stpr));
Character c=new Character(finalstr.charAt(stpr));
String s=c.toString(c);
ary[i]=s;
x=x+ary[i];
i++;
stpr++;
//first++;
}
//System.out.print(x);
String yo=x;
System.out.print(yo);
//double d = Double.valueOf(yo.trim()).doubleValue();
/*int secstpr=stpr+1;
int second=0;
while(finalstr.charAt(secstpr)!=' ')
{
System.out.print(finalstr.charAt(secstpr));
secstpr++;
second++;
}*/
//System.out.print(second);
}
}
}
所以plz幫助...
你可以嘗試'string.split()',並由4個項目組來構建一個'dict' – kev 2012-03-03 07:27:41
你可以給我一個例子.. – Taskin 2012-03-03 07:48:03