I am trying to get my program to spit out in something like this, This is HEX to
ID: 3541000 • Letter: I
Question
I am trying to get my program to spit out in something like this, This is HEX to ASCII or character conversion. Just need help. Please tell me when my for loops keeps going wrong.
Please enter the string to convert:
a+b%3A4865792074686973206973206a7573742061207072616374696365
EXPECTED OUTPUT
a b:Hey this is just a practice
but i get this below :(
Please enter the string to convert:
a+b%3A4865792074686973206973206a7573742061207072616374696365
OUTPUT:
a b%3A4865792074686973206973206a7573742061207072616374696365:::::::::::::::::::::::::::::
import java.util.Scanner;
import javax.xml.bind.Unmarshaller;
public class Unmangle {
/**
* @param args
*/
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 l = input.replace("+", " ") + outputbuild ;
return l;
}
}
Explanation / Answer
please rate - thanks
import java.util.Scanner;
import javax.xml.bind.Unmarshaller;
public class Unmangle {
/**
* @param args
*/
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;
String output;
for(int i = place ; i < input.length()-1; i +=2){
output = input.substring(i + 1, i +3);
outputbuild.append((char)Integer.parseInt(output, 16));
}
String l = input.substring(0,place);
l=l.replace("+", " ")+outputbuild ;
return l;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.