Java CSV String Convert csvEncode(int value)

Here you can find the source of csvEncode(int value)

Description

Encodes the given value to a CSV acceptable value.

License

Open Source License

Parameter

Parameter Description
value the value.

Return

the CSV encoded value.

Declaration

public static String csvEncode(int value) 

Method Source Code

//package com.java2s;

public class Main {
    private static final String ENCLOSURE = "\"";
    private static final String EMPTY = "";

    /**//from www .j  av a 2s. c  om
     * Encodes the given value to a CSV acceptable value. Returns the empty string
     * if argument is null.
     * 
     * @param value the value.
     * @return the CSV encoded value.
     */
    public static String csvEncode(int value) {
        return csvEncode(String.valueOf(value));
    }

    /**
     * Encodes the given value to a CSV acceptable value. Returns the empty string
     * if argument is null.
     * 
     * @param value the value.
     * @return the CSV encoded value.
     */
    public static String csvEncode(String value) {
        if (value == null) {
            value = EMPTY;
        } else {
            value = value.replaceAll(ENCLOSURE, ENCLOSURE + ENCLOSURE);
            value = ENCLOSURE + value + ENCLOSURE;
        }

        return value;
    }

    /**
     * Encodes the given value to a CSV acceptable value. Returns the empty string
     * if argument is null.
     * 
     * @param value the value.
     * @return the CSV encoded value.
     */
    public static String csvEncode(Object value) {
        return value != null ? csvEncode(String.valueOf(value)) : EMPTY;
    }
}

Related

  1. csvDecodeString(String value)
  2. csvDelimiter(String line)
  3. csvEncodeString(String value)
  4. csvQuote(String value)
  5. csvString(Object[] objects)
  6. csvstring(Object[] str)