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

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

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 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.

Extract a single String from an array of items

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

Communication between MS Word and other process

I have a Word document open on my desktop. I want to be able to get information about the status of the Word document, say the doc url or content. What are the means to achieve it?
Currently, I'm using JScript. However the following line only gives a new instance of Word instead of the currently open Word doc.
var word = WScript.CreateObject("Word.Application");
Any suggestion would be appreciated.
The function to use is GetObject(). It will return a pointer to the first Word instance opened.

Parsing free format text in Cocoa

My Cocoa app needs to parse free format text entered via NSTextView. The result of the process should be a collection of keyword strings which can then be displayed for review to the user and optionally persisted using Core Data.
I looked at NSScanner but from the samples in Apple's documentation it looks like it's not capable of presenting a list of keyword strings from a given string. Its focus seems to be more on finding a particular occurrence of a given string within another string.
Are there alternatives?
EDIT: To make this clearer: all words in the entered text are potential keywords, so basically all words delimited by spaces should be considered. Lets assume that the user can specify a minimum required length for a string to be considered a keyword to eliminate irrelevant words like "to", "of", "in" etc. Once the parsing is done, a list of parsed keywords should be presented (possibly using a table view). The user can then select or reject each keyword. Rejected keywords will be stored so the parsing can be made smarter as more texts are scanned.
You can absolutely use NSScanner to do this. All NSScanner does is go through a string character by character. It is up to you to decide what the keyword boundaries are and to interpret them using the scanner.
I suggest reading more about NSScanner in Apple's String Programming Guide.

Resources