Hi All
Wonder if someone could help me with what is probably a easy question. I am using Cherrio to get an array of items from a website. The data returned looks like the following in Console:
I was wondering if there is a way to remove all the white space?
pm.test("Example", function(){
const $ = cheerio.load(pm.response.text())
let getAllInstancesOfData = $("td[class='dataDark']").toArray();
let mydata= getAllInstancesOfData[1].children[0].data;
console.log(mydata);
});
Simplest way would just to replace spaces with nothing.
myData = myData.replace(' ', '');
1 Like
Hey @postnewbie2020
Maybe something like?
myData.replace(/\s+/g, '');
1 Like
Yeah, this is better than mine.
1 Like
mydata.trim()
Why not this ? am i missing something
@praveendvd - i tried that before submitting my question, and it did not remove the whitespace. Thanks though
Thats interesting is this an open api that we can try out ? did other solution works ?
Hi @danny-dainton, thanks for the suggestion. I have implemented this. However, I still get the same thing logged out in the console.
Could it be that what the console is showing, is in fact not white space? This is what I have off the assertion I am doing:
AssertionError: expected β\n\t\t\t\t\t\t9.34\n\t\t\t\t\tβ to deeply equal β9.34β
@praveendvd I guess it all depends what the structure of the string is - trim()
only removes whitespace from the beginning and the end of a string.
For example:
@postnewbie2020 It looks like you have a mixture of whitespace and different carriage returns or newlines. From the image, you have provided itβs difficult to know whatβs going on.
Can you provide an example of the HTML page itβs looking at so it will be easier to run locally rather than taking a guess
1 Like
const regex = /\t|\n/ig;
console.log(myData.replaceAll(regex, ''));
trim removes only \n and \r , not \t , \t is tab