I have a string
sReasons = "O9C2700021Not eligible for SDWCEOC3900015Service upgradeHJC3900015Service upgradeJ8C5000016Delivery Attempt";
and I need to split the above string based on the separator array
const separator = ["O9", "EO", "HJ", "J8"];
Where first 2 characters(O9) represnet code, next 4 another code(C270) & next 4 the character(0021) length of the String which is Not eligible for SDWC
Where the separator codes are unique, with 2 capital letters and will not be repeated in textMessage except inEligType
I need to create a json of the format
{
{inEligType: "O9", msgCode: "C270", msgLen: "0021", textMsg: "Not eligible for SDWC"},
{inEligType: "EO", msgCode: "C390", msgLen: "0015", textMsg: "Service upgrade"},
{inEligType: "HJ", msgCode: "C390", msgLen: "0015", textMsg: "Service upgrade"},
{inEligType: "J8", msgCode: "C500", msgLen: "0016", textMsg: "Delivery Attempt"}
}
I'm basically failing at the splitting the string itself based on the array given, I tried the following
sReasons = "O9C2700021Not eligible for SDWCEOC0900015Service upgradeHJC3900015Service upgradeJ8C5HJ0016Delivery Attempt";
const separator = ["O9", "EO", "HJ", "J8"];
function formatReasons(Reasons: string) {
var words: any[] = Reasons.split(this.spearator);
for(let word in words)
{
console.log(word) ;
}
}
var result = formatReasons(sHdnReasonsCreate);
console.log("Returned Result: "+result);
But it gives me result as
["O9C2700021Not eligible for SDWCEOC0900015Service upgradeHJC3900015Service upgradeJ8C5HJ0016Delivery Attempt"]length: 1__proto__: Array(0)
Returned Address is: undefined
textMessagefield? You'd be much better off splitting this according to the actual data format, by taking substrings of the appropriate lengthtextMessageormsgCode