Java tutorial
//package com.java2s; public class Main { public static String toStringUntil(byte[] b, int pos, byte until) { StringBuilder str = new StringBuilder(); while (true) { if (b.length <= pos) { return null; } byte ch = b[pos]; if (ch == until) { break; } str.append((char) ch); pos++; } String ret = str.toString(); return ret; } }