Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am reading an array of bytes from a page as a String. Example: "80 75 7 8 0 0".
I would like to convert this String into a byte array in Java. Can anyone help me/tell me what method I can possibly use?
Thank you.
Try:
String[] bytesString = originalString.split(" ");
byte[] bytes = new byte[bytesString.length];
for(int i = 0 ; i < bytes.length ; ++i) {
bytes[i] = Byte.parseByte(bytesString[i]);
}
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to convert an array of ints to 1 int.
e.g. I have an array of ints {1,2,3,4,5} and want to convert it to the int 12345
How do I do this?
Iterate through the array, and concatenate the values to String and convert that String to int
String valueSt = "";
for(int val : array) {
valueSt += val;
}
int finalValue = Integer.valueOf(valueSt);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm receiving a string of bytes from my server like so:
60,104,101,97,100,62,60,115,99,114,105,112
How can i convert this into a readable string?
This is what I've tried to do:
String s = new String(json.get("msg").toString());
System.out.println("Text Decryted : " + s);
But this just gives me:
60,104,101,97,100,62,60,115,99,114,105,112
Any ideas how to accomplish this?
Parse a byte array from it:
String byteString = "60,104,101,97,100,62,60,115,99,114,105,112";
String[] byteStrings = byteString.split(",");
byte[] bytes = new byte[byteStrings.length];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte)Integer.parseInt(byteStrings[i]);
}
Then interpret the bytes as a string in a particular character set. Find out which character set you're actually using, to avoid future problems.
String string = new String(bytes, java.nio.charset.StandardCharsets.UTF_8);
The above is not very efficient by the way. Since you're already sending a string from the server, it would make more sense just to send the actual string. If you can't send the string as-is, you should ask about that problem.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Please could you tell me how its work in section (g[ss[i]]++;) and tell me the sequence of output in java
class A{
public static void main(String []a){
int []ss={1,2,3,4,2,3,3,1,1,1,5,6,4,5,4};
int []g=new int[15];
for(int i=0;i<15;i++){
g[ss[i]]++;
}
for(int i=1;i<15;i++){
System.out.println(ss[i-1]+"=="+g[i]);
}
}
}
Can't you run it?
g[ss[i]]++; can be rewritten as
int index = ss[i];
g[index] = g[index] + 1;
So it's counted number of each number in ss.
It's very error prone, and you should never do something like that.
Just run it?
1==4
2==2
3==3
4==3
2==2
3==1
3==0
1==0
1==0
1==0
5==0
6==0
4==0
5==0
This should be your output.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I want to convert a hexadecimal string into IP4 string , I googled but didn't get any good way. Could anybody suggest me a simple way.
Thanks .
Please try this method.
String hexValue = "Hex IP";
String ip = "";
for(int i = 0; i < hexValue.length(); i = i + 2) {
ip = ip + Integer.valueOf(hexValue.subString(i, i+2), 16) + ".";
}
System.out.println("Ip = " + ip);
In this post the author gave a method for printing out an int into hexadecimal.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am looking for a regular expression to remove all #[x] present in a string
Where x can be any string.
For example #[title]
#\[[^\]]*\]?
As in:
String s = "asda #[asdagf] dsgfdg";
System.out.println(s.replaceAll("#\\[[^\\]]*\\]",""));
will print out:
asda dsgfdg
String original = "Hello #[world]!";
String replaced = original.replaceAll("#\\[.*?\\]", "");
// replaced = "Hello !"`enter code here`