title: TypeError: name is null when trying to replace problematic characters
body: <p>In trying to remove problematic characters from imported text via JavaScript, I receive the TypeError: Name is "null"  on this line: </p>
  
  <pre><code>for ( var i = 0; i &lt; name.length; i++) {
  </code></pre>
  
  <p>Here is the relevant section of code - </p>
  
  <pre><code>fixNameToMiniCharset : function (name) {
      if(typeof name == 'undefined') {
          com.synckolab.global.consoleService.logStringMessage("undefined string " + new Error("s").stack);
      }
      var ret = "";
      // avoid double placeholders 
      var placeHolder = false;
      for ( var i = 0; i &lt; name.length; i++) {
          switch (name.charAt(i)) {
          // character replaces... better this way
          case '\u00e4':
          case '\u00e1':
          case '\u00e0':
          case '\u00e2':
          case '\u00e3':
          case '\u00e5':
          case '\u00e6':
              placeHolder = false;
              ret += 'a';
              break;
          case '\u00c4':
          case '\u00c1':
          case '\u00c0':
          case '\u00c2':
          case '\u00c3':
          case '\u00c5':
          case '\u00c6':
              placeHolder = false;
              ret += 'A';
              break;
          case '\u00f6':
          case '\u00f3':
          case '\u00f2':
          case '\u00f4':
          case '\u00f5':
          case '\u00f8':
              placeHolder = false;
              ret += 'o';
              break;
          case '\u00d6':
          case '\u00d3':
          case '\u00d2':
          case '\u00d4':
          case '\u00d5':
          case '\u00D6':
              placeHolder = false;
              ret += 'O';
              break;
          case '\u00fc':
          case '\u00fa':
          case '\u00f9':
          case '\u00fb':
          case '\u0169':
          case '\u0171':
              placeHolder = false;
              ret += 'u';
              break;
          case '\u00dc':
          case '\u00da':
          case '\u00d9':
          case '\u00db':
          case '\u0168':
              placeHolder = false;
              ret += 'U';
              break;
          case '\u00c8':
          case '\u00c9':
          case '\u00ca':
          case '\u00cb':
              placeHolder = false;
              ret += 'E';
              break;
          case '\u00e8':
          case '\u00e9':
          case '\u00ea':
          case '\u00eb':
              placeHolder = false;
              ret += 'e';
              break;
          case '\u00ec':
          case '\u00ed':
          case '\u00ee':
          case '\u00ef':
              placeHolder = false;
              ret += 'i';
              break;
          case '\u00dd':
          case '\u00a5':
              placeHolder = false;
              ret += 'Y';
              break;
          case '\u00c7':
              placeHolder = false;
              ret += 'C';
              break;
          case '\u00e7':
              placeHolder = false;
              ret += 'c';
              break;
          case '\u00fd':
          case '\u00ff':
              placeHolder = false;
              ret += 'y';
              break;
          case '\u00df':
              placeHolder = false;
              ret += 's';
              break;
          case '\u00f1':
              placeHolder = false;
              ret += 'n';
              break;
          case '\u00b2':
              placeHolder = false;
              ret += '2';
              break;
          case '\u00b3':
              placeHolder = false;
              ret += '3';
              break;
  
          // chars which are no problem just stay
          case '_':
              // make sure to print it only once
              if(!placeHolder) {
                  ret += name.charAt(i);
                  placeHolder = true;
              }
              break;
  
          default:
              var c = name.charAt(i);
              if ((c &gt;= 'A' &amp;&amp; c &lt;= 'Z') || (c &gt;= 'a' &amp;&amp; c &lt;= 'z') || (c &gt;= '0' &amp;&amp; c &lt;= '9')) {
                  placeHolder = false;
                  ret += c;
              } else {
                  if (!placeHolder) {
                      ret += '_';
                      placeHolder = true;
                  }
              }
          }
      }
      return ret;
  </code></pre>