Java Utililty Methods Text Parse

List of utility methods to do Text Parse

  1. HOME
  2. Java
  3. T
  4. Text Parse

Description

The list of methods to do Text Parse are organized into topic(s).

Method

byte textToByte(char[] text)
text To Byte
byte result = 0;
if (text.length == 2) {
 byte[] bytes = { charToByte(text[0]), charToByte(text[1]) };
 result = (byte) ((bytes[0] << 4) + bytes[1]);
return result;
byte[] textToBytes(String text)
Convert text to bytes
byte[] baBytes = new byte[text.length() / 2];
for (int j = 0; j < text.length() / 2; j++) {
 Integer tmpInteger = Integer.decode(new String("0x" + text.substring(j * 2, (j * 2) + 2)));
 int tmpValue = tmpInteger.intValue();
 if (tmpValue > 127) 
 tmpValue = (tmpValue - 127) * -1;
 tmpInteger = new Integer(tmpValue);
 baBytes[j] = tmpInteger.byteValue();
return baBytes;
String textToCDATA(String text)
Converts a text string to HTML or XML entities.
if (text == null)
 return "null";
final StringBuffer html = new StringBuffer();
for (int i = 0; i < text.length(); i++) {
 html.append(charToCDATA(text.charAt(i)));
return html.toString();
Integer textToInteger(String filename, String text, String name)
text To Integer
if (text == null || text.length() == 0) {
 throw new Exception("Bad integer. Filename= " + filename + ", name= " + name);
Integer intValue = null;
try {
 intValue = Integer.valueOf(text);
} catch (NumberFormatException e) {
 throw new Exception("Bad integer. Filename= " + filename + ", exception= " + e.toString());
...
Integer textToInteger(String text)
text To Integer
if (text == null || text.isEmpty())
 return null;
try {
 return Integer.valueOf(text);
} catch (NumberFormatException ex) {
 return null;
String textToMMDDYYYY(String pdata)
Converte a data para MM/DD/YYYY
String aux = "";
if (!pdata.equals("__/__/____") && !pdata.equals(""))
 aux = pdata.substring(3, 5) + "/" + pdata.substring(0, 2) + "/" + pdata.substring(6);
return aux;
byte[] textToNumericFormat(String src)
Converts IPv4 address in its textual presentation form into its numeric binary form.
if (src == null || src.length() == 0) {
 return null;
int octets;
char ch;
byte[] dst = new byte[INADDRSZ];
char[] srcb = src.toCharArray();
boolean sawDigit = false;
...
byte[] textToNumericFormatV4(String host)
text To Numeric Format V
return sun.net.util.IPAddressUtil.textToNumericFormatV4(host);
byte[] textToNumericFormatV4(String ipString)
text To Numeric Format V
String[] address = ipString.split("\\.", IPV4_PART_COUNT + 1);
if (address.length != IPV4_PART_COUNT) {
 return null;
byte[] bytes = new byte[IPV4_PART_COUNT];
try {
 for (int i = 0; i < bytes.length; i++) {
 bytes[i] = parseOctet(address[i]);
...
byte[] textToNumericFormatV4(String src)
text To Numeric Format V
if (src.length() == 0) {
 return null;
byte[] res = new byte[INADDR4SZ];
String[] s = src.split("\\.", -1);
long val;
try {
 switch (s.length) {
...


AltStyle によって変換されたページ (->オリジナル) /