我试图让我的程序以这样的方式吐出,这是 HEX 到 ASCII 或字符的转换。只是需要帮助。请告诉我我的 for 循环何时出错。
Please enter the string to convert:
a+b%3A4865792074686973206973206a7573742061207072616374696365
a b:Hey this is just a practice
但我在下面得到这个:(
Please enter the string to convert:
a+b%3A4865792074686973206973206a7573742061207072616374696365
a b%3A4865792074686973206973206a7573742061207072616374696365:::::::::::::::::::::::::::::
这是我的代码
public class Unmangle {
public static void main(String[] args) {
Scanner webinput = new Scanner(System.in);
System.out.println("Please enter the string to convert: ");
String input = webinput.nextLine();
Unmangle.Unmangler(input);
String result = Unmangle.Unmangler(input);
System.out.println(result);
}
// For example, unmangle("a+b%3A") should return "a b:".
public static String Unmangler(String input) {
// if(input.contains("%"))
int place = input.indexOf("%");
StringBuilder outputbuild = new StringBuilder();
StringBuilder S;
for (int i = place; i < input.length(); i += 2) {
String output = input.substring(place + 1, place + 3);
outputbuild.append((char) Integer.parseInt(output, 16));
}
String result = input.replace("+", " ") + outputbuild;
return result;
}
}