llegal escape character followed by a space

后端 未结 2 1791
借酒劲吻你
借酒劲吻你 2021-01-28 00:09

I\'m writing a bit of code to run a shell script using process that loads and runs a file in terminal. The problem I\'m having is getting the filename to be recognised by termin

2条回答
  •  旧时难觅i
    2021-01-28 00:40

    If you want to put the \ character (which is the escape character) inside a string, you'll need to escape it:

    string = string.replaceAll (" ", "\\ ");
    

    A single \ is a escape sequence leading character, such as with \n (newline) or \r (carriage return). The full list of single-character escapes is:

    \b    backspace
    \t    tab
    \n    linefeed (newline)
    \f    form feed
    \r    carriage return
    \"    double quote
    \'    single quote
    \\    backslash
    

    This is in addition to the octal escape sequences s such as \0, \12 or \377.

    The reason why your separatorChar solution won't work is because that gives you the separator char (/ under UNIX and its brethren), not the escape character \ that you need.

提交回复
热议问题