請問怎麼樣把一串字串,截取其中幾段,然後轉成數字,再轉成十進位,
再轉成字串~~~就比如我收到 (D8F6
2007-06-26 09:54:57 · 1 個解答 · 發問者 小明 2 in 電腦與網際網路 ➔ 程式設計
//Power by Eclipse v3.2
import java.io.*;
import java.util.*;
//類別檔名 TEST_JAVA.java
public class TEST_JAVA
{
public static void main(String[] args)
{
//==========START==========//
PrintStream p=new PrintStream(System.out);
String str="(D8F6
String str2[]=new String[3],temp;
StringTokenizer strtok=new StringTokenizer(str,"<>\"() ");
for(int i=0;strtok.hasMoreTokens();i++){
temp=strtok.nextToken();
if((i%3)==0){
str2[i/3]=temp;
p.printf("%s\n",str2[i/3]);
}
}
p.printf("[%s]= %s\n",str2[2],Integer.toString(htod(str2[2])));
//==========END==========//
}
public static int htod(String hex){
char chH[]=new char[hex.length()];
chH=hex.toCharArray();
int value=0,flag;
for(int i=0;i
if(Character.isLetter(chH[flag])){
value+=(Character.toUpperCase(chH[flag])-'A'+10)*(int)Math.pow(16, i);
}else if(Character.isDigit(chH[flag])){
value+=(chH[flag]-48)*(int)Math.pow(16, i);
}
}
return value;
}
}
2007-06-26 11:16:50 · answer #1 · answered by Big_John-tw 7 · 0⤊ 0⤋