-1

I am trying to read text from a file and then format it using String.format();. The content of the file looks as follows.

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">

    <script src="../plugin/codemirror/lib/codemirror.js"></script>
    <link rel="stylesheet" href="../plugin/codemirror/lib/codemirror.css">
    <script src="../plugin/codemirror/mode/%1s/%1s.js"></script>
</head>

<body>
    <script>
        const editor = CodeMirror(document.body, {
            lineNumbers: true,
            mode: "%1s",
        });

        function changeEditorSize(width, height){
            editor.setSize(width, height);
        }
    </script>
</body>
</html>

I store the content in a variable called "content" and then attempt the following (the value of "content" is identical to the content of the file).

String.format(content, "javascript");

Then I get the error "java.util.MissingFormatArgumentException: Format specifier '%1s'" when "%1s%" is clearly in the string. Does anyone have an idea why this might be happening?

paul
  • 96
  • 9

1 Answers1

1

String.format uses $ to specify parameter indices.

You need %1$s

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964