Dark Launch

JavaScript view newlines & tabs in string

View a string's newlines and tabs in JavaScript. This function replaces line endings/newlines and tabs:

Javascript
function raw(str) {
    return str.replace(/\t/g, '\\t')
              .replace(/\r\n/g, '\\r\\n')
              .replace(/\r/g, '\\r')
              .replace(/\n/g, '\\n');
}

The /g modifier finds and replaces all occurrences.

Comments


  1. Touchdown! That's a really cool way of puitntg it!