Java String Quote quoteArg(String arg)

Here you can find the source of quoteArg(String arg)

Description

Returns the argument string surrounded with quotes if it contains a space, otherwise returns the string as is.

License

Open Source License

Parameter

Parameter Description
arg The argument string

Return

The string, optionally in quotes.

Declaration

public static String quoteArg(String arg) 

Method Source Code

//package com.java2s;
/*//from   w ww  .jav  a2  s  . co  m
 * Universal Media Server, for streaming any medias to DLNA
 * compatible renderers based on the http://www.ps3mediaserver.org.
 * Copyright (C) 2012 UMS developers.
 *
 * This program is a free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 2
 * of the License only.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

public class Main {
    /**
     * Returns the argument string surrounded with quotes if it contains a space,
     * otherwise returns the string as is.
     *
     * @param arg The argument string
     * @return The string, optionally in quotes.
     */
    public static String quoteArg(String arg) {
        if (arg != null && arg.indexOf(' ') > -1) {
            return "\"" + arg + "\"";
        }

        return arg;
    }
}

Related

  1. quoteAndClean(String str)
  2. quoteAndEscape(String str)
  3. quoteAndEscapeFilename(String filename)
  4. quoteAndEscapeValue(String serviceQName)
  5. quoteArg(final String arg)
  6. quoteArgForCommand(String input)
  7. quoteArgument(final String argument)
  8. quoteArgument(String arg)
  9. quoteAtom(String term)