I have the following text:
LOG: time="2021-12-09T16:55:25+01:00" level=debug msg="🎁 GetLatestBlock called" blockHeight=3 blockID=ee98016d268630db54b814d18d0127edac8cc36f90d193c0c6f5fd4909bbd8b1
,LOG: time="2021-12-09T16:55:25+01:00" level=debug msg="👤 GetAccountAtLatestBlock called" address=f8d6e0586b0a20c7
,LOG: time="2021-12-09T16:55:26+01:00" level=debug msg="️✉️ Transaction submitted" txID=5a46897e60f13ee68e11ef754983fefe9ec7bc8a2ca6079f0665e404138735e9
,LOG: time="2021-12-09T16:55:26+01:00" level=info msg="⭐ Transaction executed" computationUsed=6 txID=5a46897e60f13ee68e11ef754983fefe9ec7bc8a2ca6079f0665e404138735e9
,LOG: time="2021-12-09T16:55:26+01:00" level=debug msg="\x1b[1;34mLOG\x1b[0m \x1b[2m[5a4689]\x1b[0m \"Hello from Emulator\""
time="2021-12-09T16:55:26+01:00" level=debug msg="\x1b[1;34mLOG\x1b[0m \x1b[2m[5a4689]\x1b[0m 0x1cf0e2f2f715450"
time="2021-12-09T16:55:26+01:00" level=debug msg="\x1b[1;34mLOG\x1b[0m \x1b[2m[5a4689]\x1b[0m 0x179b6b1cb6755e31"
time="2021-12-09T16:55:26+01:00" level=debug msg="📦 Block #4 committed" blockHeight=4 blockID=5fd780a98baad6d30f66cf75e76c3e1c9398097a9bb2e3f239f0cd7e166f6932
,LOG: time="2021-12-09T16:55:26+01:00" level=debug msg="📝 GetTransactionResult called" txID=5a46897e60f13ee68e11ef754983fefe9ec7bc8a2ca6079f0665e404138735e9
stored in a variable called transactionLogs (, so the output you see is console.log(transactionLogs)), which is a string.
I want to check if the transaction logs contain two addresses. One from Alice 0x01cf0e2f2f715450 and one from Bob 0x179b6b1cb6755e31.
My problem is that when I call includes like this (where Alice and Bob are strings):
Alice; // 0x01cf0e2f2f715450
Bob; // 0x179b6b1cb6755e31
transactionLogs.includes(Alice); // false
transactionLogs.includes(Bob); // true
the search for Alice returns false.
I assume it has something to do with escape backslashes, so I tried running transactionLogs.replace(String.fromCharCode(92), '') but that doesn’t change the result.
What is going on here? Why is includes not returning true for Alice?
>Solution :
Why is includes not returning
truefor Alice?
Because that string is not present in the log string:
const transactionLogs = `
LOG: time="2021-12-09T16:55:25+01:00" level=debug msg="🎁 GetLatestBlock called" blockHeight=3 blockID=ee98016d268630db54b814d18d0127edac8cc36f90d193c0c6f5fd4909bbd8b1
,LOG: time="2021-12-09T16:55:25+01:00" level=debug msg="👤 GetAccountAtLatestBlock called" address=f8d6e0586b0a20c7
,LOG: time="2021-12-09T16:55:26+01:00" level=debug msg="️✉️ Transaction submitted" txID=5a46897e60f13ee68e11ef754983fefe9ec7bc8a2ca6079f0665e404138735e9
,LOG: time="2021-12-09T16:55:26+01:00" level=info msg="⭐ Transaction executed" computationUsed=6 txID=5a46897e60f13ee68e11ef754983fefe9ec7bc8a2ca6079f0665e404138735e9
,LOG: time="2021-12-09T16:55:26+01:00" level=debug msg="\x1b[1;34mLOG\x1b[0m \x1b[2m[5a4689]\x1b[0m \"Hello from Emulator\""
time="2021-12-09T16:55:26+01:00" level=debug msg="\x1b[1;34mLOG\x1b[0m \x1b[2m[5a4689]\x1b[0m 0x1cf0e2f2f715450"
time="2021-12-09T16:55:26+01:00" level=debug msg="\x1b[1;34mLOG\x1b[0m \x1b[2m[5a4689]\x1b[0m 0x179b6b1cb6755e31"
time="2021-12-09T16:55:26+01:00" level=debug msg="📦 Block #4 committed" blockHeight=4 blockID=5fd780a98baad6d30f66cf75e76c3e1c9398097a9bb2e3f239f0cd7e166f6932
,LOG: time="2021-12-09T16:55:26+01:00" level=debug msg="📝 GetTransactionResult called" txID=5a46897e60f13ee68e11ef754983fefe9ec7bc8a2ca6079f0665e404138735e9
`;
const Alice = `0x01cf0e2f2f715450`;
const Bob = `0x179b6b1cb6755e31`;
console.log({
Alice: transactionLogs.includes(Alice),
Bob: transactionLogs.includes(Bob),
});