Java String Quote quoteArg(final String arg)

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

Description

quote Arg

License

Open Source License

Declaration

private static String quoteArg(final String arg) 

Method Source Code

//package com.java2s;
// This code is made available under the terms of the Eclipse Public License,

public class Main {
    private static String quoteArg(final String arg) {
        if (arg.indexOf(' ') > -1 || arg.indexOf('\t') > -1 || arg.indexOf('"') > -1) {
            if (arg.charAt(0) != '"' && (arg.charAt(arg.length() - 1) != '"')) {
                StringBuilder sb = new StringBuilder();
                sb.append("\""); //$NON-NLS-1$
                sb.append(arg.replace("\"", "\"\"")); //$NON-NLS-1$ //$NON-NLS-2$
                sb.append("\""); //$NON-NLS-1$
                return sb.toString();
            }/*from w  w w.  j a  v a  2  s .c o m*/
        }

        return arg;
    }
}

Related

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