我正在编写一个程序,它将获取文本区域的内容,提取重要信息,格式化然后输出。
我已经成功地让我的程序将所有信息传递到一个数组中。
目前我正在努力让程序识别客户姓名的位置(如果“详细信息”不在数组中的正确位置,它将始终位于“名称”和“详细信息”或“客户”之间。
// 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) {
我不明白为什么。对我的逻辑的任何帮助也将不胜感激。
谢谢你们。:)