2

I'd like to achieve something like this:

String sentence = "Hi there over there";
String[]result = sentence.split("there");
//you get result[0] = Hi, result[1] = over

Is it possible to split using the String in a byte array format?

byte[]delimiter = "there".getBytes();
byte[]byteSentence = sentence.getBytes();
//then somehow split byteSentence using delimiter.

1 Answer 1

5

You can, of course, convert the byte arrays into strings:

byte[] delimiter = "test".getBytes();
byte[] sentence = "this is a test sentence".getBytes();

String[] result = new String(sentence).split(new String(delimiter));
byte[][] resultByte = new byte[result.length][];
for(int i = 0; i < result.length; i++){
    resultByte[i] = result[i].getBytes();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.