Store partial text of a line

I am very new to coding so forgive my ignorance and thanks for any help in advance!

I am using the command “Store text” and selecting the target. Then using a variable to store the text for later use. Everything works, but because the target returns more text than I need, I’m not sure what to do.

Example: There is a section on a webpage that says “Estimate Code: DS4582” That is one string in the target. I am only needing the number after the "Estimate Code: " part. So basically I am trying to extract just the DS4582 but cant seem to figure out how.

I have tried to use extract but that didnt work either. Any ideas?

1 Like
  • use storeText to get the complete string (just like you did!)

  • use storeEval with split to get the substring after the “:”

Test: Output is [echo] t= DS4582

{
  "Command": "store",
  "Target": "“Estimate Code: DS4582",
  "Value": "t"
},
{
  "Command": "storeEval",
  "Target": "s1 = \"${t}\"; r = s1.split (\":\"); var s2 = r[1]; s2",
  "Value": "t"
},
{
  "Command": "echo",
  "Target": "t=${t}",
  "Value": ""
}
2 Likes

Thanks, the text that is originally stored will change every time the macro is ran. Here is the code. It says line 2 error * Error in runEval code: Invalid or unexpected token.

Basically, i want the alphanumeric code after the “estimate code:” copied to the clipboard so i can paste (type) it in another section.
{
“Name”: “copy estimate code”,
“CreationDate”: “2019-1-31”,
“Commands”: [
{
“Command”: “storeText”,
“Target”: “//*[@id=“quoteOverlayDomId”]/div[2]/div[5]”,
“Value”: “t”
},
{
“Command”: “storeEval”,
“Target”: “s1 = \”${t}\"; r = s1.split (\":\"); var s2 = r[1]; s2",
“Value”: “t”
},
{
“Command”: “echo”,
“Target”: “t=${t}”,
“Value”: “”
}
]
}

“Error in runEval code: Invalid or unexpected token.” => Maybe your extracted strings contains line breaks? Then use first this to remove the line breaks:

a = storedVars['t']; a = a.replace(/(\n|\r)/gm, ""); a

I copied this line from the DemoPDFTest_with_OCR macro that ships with Kantu.

so put that at the top of the code before anything else?

Yes. After the extraction with storeText but before any other storeEVAL.