Method from jxl.biff.StringHelper Detail: |
public static byte[] getBytes(String s) {
return s.getBytes();
} Deprecated!
Gets the bytes of the specified string. This will simply return the ASCII
values of the characters in the string |
public static byte[] getBytes(String s,
WorkbookSettings ws) {
try
{
return s.getBytes(ws.getEncoding());
}
catch (UnsupportedEncodingException e)
{
// fail silently
return null;
}
}
Gets the bytes of the specified string. This will simply return the ASCII
values of the characters in the string |
public static void getBytes(String s,
byte[] d,
int pos) {
byte[] b = getBytes(s);
System.arraycopy(b, 0, d, pos, b.length);
}
Gets the ASCII bytes from the specified string and places them in the
array at the specified position |
public static String getString(byte[] d,
int length,
int pos,
WorkbookSettings ws) {
if( length == 0 )
{
return ""; // Reduces number of new Strings
}
try
{
return new String(d, pos, length, ws.getEncoding());
// byte[] b = new byte[length];
// System.arraycopy(d, pos, b, 0, length);
// return new String(b, ws.getEncoding());
}
catch (UnsupportedEncodingException e)
{
logger.warn(e.toString());
return "";
}
}
Gets a string from the data array using the character encoding for
this workbook |
public static byte[] getUnicodeBytes(String s) {
try
{
byte[] b = s.getBytes(UNICODE_ENCODING);
// Sometimes this method writes out the unicode
// identifier
if (b.length == (s.length() * 2 + 2))
{
byte[] b2 = new byte[b.length - 2];
System.arraycopy(b, 2, b2, 0, b2.length);
b = b2;
}
return b;
}
catch (UnsupportedEncodingException e)
{
// Fail silently
return null;
}
}
Converts the string into a little-endian array of Unicode bytes |
public static void getUnicodeBytes(String s,
byte[] d,
int pos) {
byte[] b = getUnicodeBytes(s);
System.arraycopy(b, 0, d, pos, b.length);
}
Inserts the unicode byte representation of the specified string into the
array passed in |
public static String getUnicodeString(byte[] d,
int length,
int pos) {
try
{
byte[] b = new byte[length * 2];
System.arraycopy(d, pos, b, 0, length * 2);
return new String(b, UNICODE_ENCODING);
}
catch (UnsupportedEncodingException e)
{
// Fail silently
return "";
}
}
Gets a string from the data array |
public static final String replace(String input,
String search,
String replace) {
String fmtstr = input;
int pos = fmtstr.indexOf(search);
while (pos != -1)
{
StringBuffer tmp = new StringBuffer(fmtstr.substring(0, pos));
tmp.append(replace);
tmp.append(fmtstr.substring(pos + search.length()));
fmtstr = tmp.toString();
pos = fmtstr.indexOf(search, pos+replace.length());
}
return fmtstr;
}
Replaces all instances of search with replace in the input.
Even though later versions of java can use string.replace()
this is included Java 1.2 compatibility |