我需要从这种字符串中获取“付款类型和客户类型
Examples:
| D | A | B | C |
| NZ | AAA | BBB | NZ |
| AZ | CCC | DDD | AZ |
| CA | EEE | FFF | CA |
我应该尝试获取模式并为此编写函数吗?或者我可以找到一些图书馆来检测它
因此输出应为{付款:[“ AAA”,“ CCC”,'EEE'],客户:[“ BBB”,'DDD“,” FFF“]}
function detect(str){
let countBar=1
let countBar2=0
let paymentLoc=NaN
let customerLoc=NaN
let after =0
let arr1=str.split(" ")
arr1=arr1.filter(item=>{return item!==""})
let newStr=''
for(let i=0;i<arr1.length;i++){
arr1[i].trim()
if(arr1[i]==='|'){
countBar++
}
if(arr1[i]==="||"){
countBar2++
}
if(arr1[i].includes("payment")){
paymentLoc=i
}
after=((countBar/(countBar2))-1)*2
let sol=[]
for(let i=0;i<arr1.length;i++){
if(arr1[i].includes("payment")){
console.log('payment index',i)
sol.push(arr1[i+after+1])
}
if(arr1[i].includes("customer")){
console.log('customer index',i)
sol.push(arr1[i+after+1])
}
}
newStr=arr1.join('')
console.log(newStr)
}
qq_花开花谢_0
相关分类