Extract a single String from an array of items - yahoo-pipes

A similar question was asked a few years ago, but the accepted answer is vague at best and confusing at worst.
I'm attempting to pass a number that I've retrieved via Regex from a fetched page as the source of a filter.
Here's the link to my pipe: http://pipes.yahoo.com/pipes/pipe.info?_id=4c087880efe5ef2ea62261ff9e7eee1b
I need to get the emitted value from the loop (which is currently 555) and pass that to the string builder so that it prepends a #; I will then pass that built string as the source for my greater than filter on the item.title of the fetched RSS feed.
Since the loop module outputs an array, I currently can't find a way to connect it to the string builder module.

Within for loop we can either get one String from list of String or we can use split("") method to divide String into words

Related

how to make Google sheets REGEXREPLACE return empty string if it fails?

I'm using the REGEXREPLACE function in google sheets to extract some text contained in skus. If it doesn't find a text, it seems to return the entire original string. Is it possible to make it return an empty string instead? Having problems with this because it doesn't actually error out, so using iserror doesn't seem to work.
Example: my sku SHOULD contain 5 separate groups delimited by the underscore character '_'. in this example it is missing the last group, so it returns the entire original string.
LDSS0107_SS-WH_5
=REGEXREPLACE($A3,"[^_]+_[^_]+_[^_]+_[^_]+_(.*)","$1")
Fails to find the fifth capture group, that is correct... but I need it to give me an empty string when it fails... presently gives me the whole original string. Any ideas??
Perhaps the solution would be to add the missing groups:
=REGEXREPLACE($A1&REPT("_ ",4-(LEN($A1)-LEN(SUBSTITUTE($A1,"_","")))),"[^_]+_[^_]+_[^_]+_[^_]+_(.*)","$1")
This returns space as result for missing group. If you don't want to, use TRIM function.

How can I shorten a string to a specific number of words?

I linked google sheet file to a app and displayed all 'data' in list view, those are long sentences and I want to make it so only the first 5 words are displayed, not the whole thing
link to the excel list: https://docs.google.com/spreadsheets/d/1L2YPoJ0KH8OB80j-9wXHJ33SP0YB0aEI0xPt4nTzLpc/export?format=csv
String myString="This is a string that is very long and tiring";
//get 10 characters max from the string
String formatedString=myString.substring(0,10);
System.out.println(formatedString);
You might want to use the Google Visualization API... There you can use SQLish commands...
For an example how to use the API in App Inventor see here https://puravidaapps.com/spreadsheet.php#select

Encode array to fixed length string

I'm trying to implement a similar function to PCPartPicker's list permalink function.
https://au.pcpartpicker.com/list/
basically generate a permalink based on the items in the list. The key part is to generate a string which should be:
unique
persistent
fixed length
I'm thinking about encoding an array contains product id, but can't find the right way to implement it.
Base64 and the similar (like Hashids library) can ensure it's unique and persistent, but it ends up quite long when the array has many items.
Is there other way to encode the array or is there other direction I can implement this function?
Thank you in advance.
One can't generate unique fixed length string for arbitrary length list that will contain all info - there is always some length that can't fit.
Since your site has database, you can generate UUID and store list in DB along with UUID. To save space and efforts you can save it into DB only when user presses "get permalink" button or something like that.

How to avoid exception by mapping string to number in thymeleaf?

I have some HTML page and on this page I will provide the possibility for free text.
For example, it is possible to write in textbox either: 10 or 10 apples.
In a case of writing 10 apples I got NumberFormatException which is correct, but for me will be good to extract only number automatically without javascript writing.
Is it possible to map string from HTML page to the number in my java entity? May be with some annotation or somehow else?
Try:
final String stripped = textbox.getText().replaceAll("[^0-9]", "");
This takes the contents of the text field and strips out any characters that aren't digits. If you need to deal with floating point or negative numbers, it can be done, but becomes more complicated.

Need to count the number of emails in a string using Capybara/RSpec

So I have an application which holds multiple entries that are strings of comma separated emails. The strings live in text area elements where they can be modified. The application uses JavaScript to modify these strings, I need to use Capybara to watch verify that a target string has the correct number of emails in it. To illustrate what I mean here's my Cucumber (assuming the target list starts with a 5 email string):
When I remove the 3rd email under list one
Then I should see 4 emails under list one
When I click the "Cancel" button for list one
Then I should see 5 emails under list one
I can pretty easily grab the string with Capybara like so:
expect(page).to have_css(".css-selectors textarea")
but I don't know what to do from there. I need to be able to assert that the number of emails in the string is in fact changing to the desired number. I need to split the string and count the number of emails to see if they match the target number, but everything I've tried leads to a race condition where Capybara checks the value before the JS can finish updating. I've looked into passing a filter block to the have_css call but I can't find documentation on how that would work, or if it's even the right tactic. And so I'm out of ideas here.
Since all the emails are in one element your inclination to use a filter block is exactly correct. The filter block receives each element that matches the initial selector and needs to return whether or not it matches whatever extra filtering you wish to do (true/false). Therefore, to check that the element had a string (value not text since it's a form field) with 4 comma separated items it would be something like
expect(page).to have_css(".css-selectors textarea"){ |ta|
ta.value.split(',').size == 4
}
This will then use Capybaras waiting/retrying behavior while also performing the extra step of checking for a matching number of comma separated items in the text of the element, thereby getting around the race condition.
Your check could also be performed by using a regex for the with option of the field selector, along the lines of
expect(page).to have_field(type: 'textarea', with: /^[^,]+,[^,]+,[^,]+,[^,]+$/)
or fillable_field selector
expect(page).to have_selector(:fillable_field, type: 'textarea', with: /^[^,]+,[^,]+,[^,]+,[^,]+$/)
Those don't currently scope to the .css-selectors element but you could do that with within or a chained find. You could also ensure a unique element by passing the id/name/label text of the element. Obviously you could make the regex more complicated if you want to actually verify the text strings are emails, etc.

Resources