Java String Quote quoteExecutable(String executable)

Here you can find the source of quoteExecutable(String executable)

Description

Surrounds the executable with double quotes if a blank is in the path.

License

Open Source License

Parameter

Parameter Description
executable the executable (full path, no parameters)

Return

the processed executable

Declaration

public static String quoteExecutable(String executable) 

Method Source Code

//package com.java2s;
/*/*  w w  w .  j a  v  a2s.  c  o  m*/
 *   This program is 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, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   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, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Surrounds the executable with double quotes if a blank is in the path.
     *
     * @param executable   the executable (full path, no parameters)
     * @return      the processed executable
     */
    public static String quoteExecutable(String executable) {
        String result;

        result = executable;
        if (result.indexOf(' ') > -1)
            result = "\"" + result + "\"";

        return result;
    }
}

Related

  1. quotedString(String text)
  2. quotedStringOrNull(String string)
  3. quoteEach(String string)
  4. quoteEscape(final String original)
  5. quoteEscaped(String input)
  6. quoteFileName(String filename)
  7. quoteForBatchScript(String arg)
  8. quoteForCommandString(String s)
  9. quoteForCsv(final String field)