I would like to transform a Java String str
into byte[] b
with the following characteristics:
b
is a valid C string (ie it hasb.length = str.length() + 1
andb[str.length()] == 0
.- the characters in
b
are obtained by converting the characters instr
to 8-bit ASCII characters.
What is the most efficient way to do this — preferably an existing library function? Sadly, str.getBytes("ISO-8859-1")
doesn't meet my first requirement...
for
loop that truncates the high-order byte and said "golly, there has to be a better way"? If after my search I didn't locate any other way besides that andstr.getBytes()
, which I mentioned, how do I represent NO IDEA in code for you?