I have a variable with this string:
Total price: 65.09 GBP
How do I extract the number 65.09 from this string and store in another variable? P.s: just the number with 2 decimals, don't need the currency after it, also, the value can be anything from 0 to 1 billion, so it could have commas also to separate the numbers.
I saw some other posts regarding this same issue using split with delimiters or substr(), but I could not adapt it to my scenario, thanks!
I would use a regular expression to extract the number:
<tr>
<td>store</td>
<td>Total price: 65.09 GBP</td>
<td>v1</td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['v1'].match(/[\d.,]+/)</td>
<td>v2</td>
</tr>
<tr>
<td>echo</td>
<td>${v2}</td>
<td></td>
</tr>
Related
Is there a way to format the numbers on the y-axis the tooltip value? Ex, I want the numbers to be delimited by commas. 1000 -> 1,000. 1000000 -> 1,000,000
You can use the thousands option for this:
<%= line_chart data, thousands: "," %>
In Adobe Business Catalyst, it stores dates in ISO 8601 format E.G. 1989-08-01T00:00:00
They provide a means of retrieving these dates like so:
{module_data resource="customers" version="v3" fields="firstName,middleName,anniversary" skip="0" limit="10" where="\{'id':'{{memberId}}'\}" order="id" collection="crmData"}
Which outputs the following for anniversay:
[anniversary1, 1987-08-01T00:00:00][anniversary1Title, Start Year][anniversary2, 1989-08-01T00:00:00][anniversary2Title, End Year][anniversary3, ][anniversary3Title, ][anniversary4, ][anniversary4Title, ][anniversary5, ][anniversary5Title, ]
I would like to retrieve only the records with a certain year (E.G. 1989). I've tried the following, but I'm pretty sure 'contains' is the wrong way to be going about this:
{module_data resource="customers" version="v3" fields="id,firstName,lastName" skip="0" limit="10" where="\{'anniversary.anniversary2':\{'$contains':'1989'\}\}" order="id" collection="crmData"}
I can find the record I'm looking for when I hard code the date (including month and year):
{module_data resource="customers" version="v3" fields="id,firstName,lastName" skip="0" limit="10" where="\{'anniversary.anniversary2':'1989-08-01'\}" order="id" collection="crmData"}
Just need a little help to make this work when I only know the year. Thanks in advance.
This does the trick.
{% assign first = "2016-01-01T00:00:00" -%}
{{first}}
{% assign last = "2017-01-01T00:00:00" -%}
{{last}}
{module_data resource="customers" version="v3" fields="id,firstName,lastName" skip="0" limit="10" where="\{'$and':\[\{'anniversary.anniversary1':\{'$lt':'{{last}}'\}\},\{'anniversary.anniversary1':\{'$gt':'{{first}}'\}\}\]\}" order="id" collection="myData"}
<div>
<pre>{{myData|json}}</pre>
</div>
Let me know if you need more help.
In data-sly-list I can loop through elements as in following examples
data-sly-list: Repeats the content of the host element for each enumerable property in the provided object.However, what if I want to loop through the first 4 elements or from 8th till 10th elements, how to do so?
Here is a simple loop:
<dl data-sly-list="${currentPage.listChildren}">
<dt>index: ${itemList.index}</dt>
<dd>value: ${item.title}</dd>
</dl>
Use something like this:
<dl data-sly-list="${currentPage.listChildren}">
<div data-sly-test="${itemList.count > 4 && itemList.count <8}" data-sly-unwrap>
<dt>index: ${itemList.index}</dt>
<dd>value: ${item.title}</dd>
</div>
</dl>
You can use either of count or index variable.
I have a web page containing a table, where each row has either class vc_row_odd or vc_row_even, like this. The table has about 3000 rows, but using jsoup I am retrieving only about half of them.
I have looked at the source page, and the rows seem consistently structured. Why is jsoup selector not finding all rows I wonder ?
Here below is my jsoup code:
Document doc = Jsoup.connect(url).header("Authorization",
"Basic " + base64login).timeout(10 * 1000).get();
Elements trs = doc.select("tr[class~=vc_row_(odd|even)]");
logger.debug("Size trs " + trs.size());
<tr class="vc_row_odd">
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
<tr class="vc_row_even">
<td>...</td>
<td>...</td>
<td>...</td>
<td>...</td>
</tr>
Found solution with setting maxSizeLimit to zero
http://jmchung.github.io/blog/2013/10/25/how-to-solve-jsoup-does-not-get-complete-html-document/
Just ran into this myself, the link in the existing self-answer is dead, but according to the latest archived version[1], the option is called maxBodySize[2], not maxSizeLimit. The default is 1MB, setting it to zero turns the limit off.
Document doc = Jsoup.connect(DATA_URL).maxBodySize(0).get();
Sources:
[1] https://web.archive.org/web/20180209022028/http://jmchung.github.io/blog/2013/10/25/how-to-solve-jsoup-does-not-get-complete-html-document/
[2] https://jsoup.org/apidocs/org/jsoup/Connection.html#maxBodySize-int-
Im parsing a table using hpple and libxml2 in an iPhone app. I have encountered a real problem when it comes to finding the column index when sibling cells span multiple rows using colspan.
I saw this question
But I can't use jquery to work out the column.
Consider the following table
<table>
<tbody>
<tr>
<td>One</td>
<td>Two</td>
<td id="example1">Three</td>
<td>Four</td>
<td>Five</td>
<td>Six</td>
</tr>
<tr>
<td colspan="2">One</td>
<td colspan="2">Two</td>
<td colspan="2" id="example2">Three</td>
</tr>
<tr>
<td>One</td>
<td>Two</td>
<td>Three</td>
<td>Four</td>
<td>Five</td>
<td>Six</td>
</tr>
</tbody>
</table>
How can i get the column index as 6 NOT 3 for the cell with id 'example1'?
EDIT Added more detail
NSString *xpathQuery = [NSString stringWithFormat:#"1
+ count(//a[contains(#href,'testHref')]
/../preceding-sibling::td[not(#colspan)])
+ sum(//a[contains(#href,'testHref')]/../preceding-sibling::td/#colspan)
+ sum(#colspan)
- count(#colspan)",bookingUrl, bookingUrl];
//Execute XPath
NSArray *array = [parser searchWithXPathQuery:columnCount];
This seems to work:
1 + count(preceding-sibling::td[not(#colspan)])
+ sum(preceding-sibling::td/#colspan)
+ sum(#colspan)
- count(#colspan)
Running the xpath for the <td> as the current node.