Java String Quote quote(final String value)

Here you can find the source of quote(final String value)

Description

Quote the given string if needed

License

Apache License

Parameter

Parameter Description
value The value to quote (e.g. bob)

Return

The quoted string (e.g. "bob")

Declaration

public static String quote(final String value) 

Method Source Code

//package com.java2s;
/*//w  ww .  ja  v a2s  .  co m
 * Copyright (c) 2016 Network New Technologies Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Quote the given string if needed
     *
     * @param value The value to quote (e.g. bob)
     * @return The quoted string (e.g. "bob")
     */
    public static String quote(final String value) {
        if (value == null) {
            return null;
        }
        String result = value;
        if (!result.startsWith("\"")) {
            result = "\"" + result;
        }
        if (!result.endsWith("\"")) {
            result = result + "\"";
        }
        return result;
    }
}

Related

  1. quote(final String str)
  2. quote(final String str)
  3. quote(final String str)
  4. quote(final String sValue)
  5. quote(final String value)
  6. quote(final String value)
  7. quote(Object aObject)
  8. quote(Object s)
  9. quote(Object s)