public static String escapeStringLiteral(String s) {
    StringBuilder sb = null;
    int len = s.length();
    int lastIndex = 0;
    for (int i = 0; i < len; i++) {
      String replacement = escapeCharacterForStringLiteral(s.charAt(i), s, i);
      if (replacement == null) {
        continue;
      }
      if (sb == null) {
        sb = new StringBuilder();
      }
      if (lastIndex < i) {
        sb.append(s.substring(lastIndex, i));
      }
      lastIndex = i + 1;
      sb.append(replacement);
    }
    if (sb != null) {
      sb.append(s.substring(lastIndex, len));
      return sb.toString();
    } else {
      return s;
    }
  }
public static String escapeStringLiteral ( String s ) { StringBuilder sb = null ; int len = s . length ( ) ; int lastIndex = 0 ; for ( int i = 0 ; i < len ; i ++ ) { String replacement = escapeCharacterForStringLiteral ( s . charAt ( i ) , s , i ) ; if ( replacement == null ) { continue ; } if ( sb == null ) { sb = new StringBuilder ( ) ; } if ( lastIndex < i ) { sb . append ( s . substring ( lastIndex , i ) ) ; } lastIndex = i + 1 ; sb . append ( replacement ) ; } if ( sb != null ) { sb . append ( s . substring ( lastIndex , len ) ) ; return sb . toString ( ) ; } else { return s ; } }
Returns a valid ObjC string literal (excluding quotes).