配列要素が唯一の新しい行が含まれているかどうかを確認する方法?

StackOverflow https://stackoverflow.com/questions/933476

  •  06-09-2019
  •  | 
  •  

質問

段落と、いくつかの空白行で構成されたプレーンテキストファイルは、Ajaxを経由して、アレイにロードされます。

:アレイは、以下のような新たな株による要素に分割され
var infoArray = new Array();
infoArray = response.split("\n");

次に、アレイは、次のn-要素が特定の方法で処理され得る示す様々な要素、のキーワードのための種々の試験と、forループに通されます。大部分の要素のような出力は、ある

    strMsg += '<li>' + infoArray[i] + '</li>';
テキストファイルから

問題がある空白行も、配列の要素に保存されています。そして、空白のリスト項目は、出力を取得し、著しく間違っています。

配列要素が空であるか、改行文字が含まれている場合にだけチェックするために、私が適用されるかわからないテスト条件が必要です。プラスサーバーはバグがあり、時には、私は時々私は私の最も最近のコードを更新するか、いないですかはわからないので、新しい情報をロードするために分かかります。

私が試したことのいくつか:

    if (!(infoArray[i].substring(0,0) == '')) { /* process output */ }
    if (!(infoArray[i].substring(0,1) == '\n')) { /* process output */ }
    if (!(infoArray[i].substring(0,0) == '\n')) { /* process output */ }
    if (!(infoArray[i].substring(0,1) == /\n/)) { /* process output */ }
    if (!(infoArray[i].substring(0,1) == /\n/)) { /* process output */ }
    if (!(infoArray[i].substring(0,1) == /\n|\s*\n/)) { /* process output */ }
    if (!(infoArray[i].IsEmpty())) { /* process output */ }

    var tempString = infoArray[i].toString();
    if (!(tempString.IsEmpty())) { /* process output */ }
    if (tempString.length != 0) { /* process output */ }

アイデア?

編集:そうそう、私はまた、「\ n」はちょうどそれを引き出すためにチェックする前に、「エンコード」および「復号」をやってみました。

正しい解決策はありません

scroll top