私は、テキスト領域の内容を取得し、重要な情報を引き出し、フォーマットしてから出力するプログラムを作成しています。
プログラムですべての情報を配列に渡すことに成功しました。
現在、私はプログラムで顧客の名前がどこにあるかを特定するように取り組んでいます(「詳細」が配列内の正しい場所にない場合は、常に「名前」と「詳細」または「顧客」の間にあります。
// Parse the input box into an array
var inputArr = document.getElementById("inputBox").value.split(/[\s]/);
// Instantiate variables
var custDet, contactName, phone, companyName, email;
// Pull out all strings between "Name" and "Email" ("Card" should always be after "Email" or else it's the wrong string
if(inputArr[inputArr.indexOf("Email") + 1] == "Card") {
custDet = inputArr.slice(inputArr.indexOf("Name") + 1, inputArr.indexOf("Email"));
// Pass the customer's name into the string contactName
for(i = 0; custDet[i] != "Details" || custDet[i] != "Customer" || i < custDet.length; i++) {
if(custDet[i].search(",") != -1) {
var temp = custDet[i].split(/[,]/);
temp.reverse();
contactName = contactName + temp.join(" ");
}
}
contactName = contactName + custDet.join(" ");
} else {
contactName = prompt("Error: Could not locate a valid Contact Name. Please input Contact Name.");
phone = prompt("Error: Could not locate a valid Contact Phone Number. Please input Contact Phone Number.");
companyName = prompt("Error: Could not locate a valid Company Name. Please input Company Name.");
email = prompt("Error: Could not locate a valid Email Address. Please input Email Address.");
}
エラーがスローされています...
if(custDet[i].search(",") != -1) {
そして、その理由がわかりません。私の論理についての助けもいただければ幸いです。
皆さん、ありがとうございました。:)