Google Spreadsheet CHECKSTRING(url ; string) (new function needed) - google-sheets

I’m really new to programming so first of all I beg your pardon for my my questions.
I would like to create a function to search the webpage of a site in order to find any string is present.
This function could be written like this. Thanks in advance for your precious help. Then How I can activate it to use it in a cell.
Thanks for your precious help.
Seb
--
CHECKSTRING(url ; string)
• url - The URL of the web page to examine, including protocol (e.g. http:// or https://).
The value for url must either be enclosed in quotation marks or be a reference to a cell containing the appropriate text.
• String – The STRING to find in the page source from the URL. The value for String must either be enclosed in quotation marks or be a reference to a cell containing the appropriate text.
This function returns the line number position at which the STRING is first found within URL code source, case-sensitive.
This function returns -1 or FASE when the check answer is negative.

Did you try the FINDfunction ?
=iferror(find(string_to_search, url), false)
or, depending on your locale:
=iferror(find(string_to_search; url); false)
where string or URL can be passed in as string, or as cell references.
NOTE: if you want to do a case-insensitve search, replace the FIND() with SEARCH()

Related

Function call / Referencing from within a string

IMPORTDATA("https://min-api.cryptocompare.com/data/price?fsym=DOGE&tsyms=INR")
I have the above given function, and I have to call this function again with different parameters i.e. "DOGE" and "INR" will have to be replaced with a new set of parameters.
But I am not able to figure out how to reference cell within the url here.
Column_Reference The column which has to be iterated over looks like this.
I tried using cell reference directly, string manipulation but it didn't work as it didn't recognise it as a formula.
IMPORTDATA("https://min-api.cryptocompare.com/data/price?fsym=A2&tsyms=INR")
IMPORTDATA("https://min-api.cryptocompare.com/data/price?fsym=LEFT(A2,10)&tsyms=INR")
Please use this formula and drag down
=IMPORTDATA("https://min-api.cryptocompare.com/data/price?fsym="&B2&"&tsyms=INR")

How to extract URL from link (link feature, not HYPERLINK formula) in Google Sheets?

Google Sheets allows to specify (hyper)links in two ways:
By using HYPERLINK formula/function, e.g. =HYPERLINK("http://example.com/", "Example.com")
By using "linking" feature – Insert » Insert Link
There are a lot of solutions around the web, and StackOverflow, for extracting URL from the first option - the HYPERLINK formula, but I haven't found any way how to extract it from the second option.
Example Sheet
How to extract with Apps Script a link URL inserted with Insert » Insert Link
Apps Script has a class https://developers.google.com/apps-script/reference/spreadsheet/rich-text-value that allows you to retrieve not only the plain text contained in a cell, but also its properties, such as the link URL.
To access this property use the method getRichTextValue() combined with getLinkUrl()
Sample to retrieve the link URL in a custom function:
function getLink(range){
var link = SpreadsheetApp.getActive().getActiveSheet().getRange(range).getRichTextValue().getLinkUrl();
return link;
}
After writing and saving this code, you simply need to call it from any cell, giving it the reference of the cell with the link URL as parameter.
Important:
Since it is the reference and not the value of the cell that should be passed to the function, you need to put the A1 notation in quotes.
Sample:
=getLink("A1")
We can improve ziganotschka's solution to avoid the need for quotation marks.
Enter this in B1 (assuming text with the embedded link is in A1):
=getLink(ADDRESS(row(),column(A1)))
This way it can be dragged down to quickly get data for an entire column.
If want to use like normal formula without quotation marks,
function GetURL(input) {
var formula = SpreadsheetApp.getActiveRange().getFormula();
var rx = /=geturl\((.*)\)/gi;
var rng_txt = rx.exec(formula)[1]
var rng = SpreadsheetApp.getActiveSheet().getRange(rng_txt);
return rng.getRichTextValue().getLinkUrl()
}

Any reason for URLEncodedUtils.parse return List< NameValuePair >

https://hc.apache.org/httpcomponents-client-4.3.x/httpclient/apidocs/org/apache/http/client/utils/URLEncodedUtils.html#parse(java.net.URI,%20java.lang.String)
why not return Map< String, List< String > >
if it returns Map, user can easily query by key to get whatever they want.
otherwise user should iterator the whole list to find what they want.
Thanks
Because this is a list. If you read carefully the explanation, says:
Returns a list of NameValuePairs as built from the URI's query portion. For example, a URI of http://example.org/path/to/file?a=1&b=2&c=3 would return a list of three NameValuePairs, one for a=1, one for b=2, and one for c=3.
That means that you cannot use a list to acces by value, because these type of data structures aren't designed for that. They doesn't have any "key" to use.
In this website, Jon Skeet wrote a very clear answer about you cannot use a shortcut to acces a List<NameValuePair> value using a name or a key or for similar structures.
Here you can check the post: Get ArrayList<NameValuePair> value by name
Inside of the same post, you'll see different options to solve your problem. (Or could guide to you to find the solution)

Replace a string with another in request.rawurl not working

I want to replace some string in my url like this
request.RawUrl.ToString().Replace("sometext566666", "othertest")
but it s not working why is it so?
For example, the original url is like
/sometext4554544454.aspx
and I want it like this
/sometext.aspx
I'm guessing that this is .NET. If so, you should be aware the String.Replace() returns a new string containing the result of the replacement (as do all other methods that purport to modify a string).
So you need to assign the result to a variable or field to hold the result. In some circumstances, you might assign the result back to the same place you obtained the original string from. But you're not allowed to overwrite RawUrl (and, it would be potentially confusing for you to do so).
The statement you are using is working, but you are not assigning the result of the replace function, just executing it.
request.RawUrl.ToString().Replace("sometext566666", "othertest")
If you want to keep the result, you will need to assign it to a string.
e.g.
String result = request.RawUrl.ToString().Replace("sometext566666", "othertest");
Otherwise, you can assign it to the same RawURL but I think that is a URI so you'll need to use a new URI, something like:
request.RawUrl = new URI(request.RawUrl.ToString().Replace("sometext566666", "othertest"));
Nevertheless, I'm not sure if you can actually edit that property.

Passing url as parameter to web service method

I'm writing a web service which expects one of the parameters (called "hlink") to be a url. Before calling the web service I URLEncode the parameter in question ("hlink"). I then call the web service with an hlink parameter value of 'a.apsx?a=1&b=2. When the request arrives at the web service method I can examine hlink - it has received the url ok, but only as "a.aspx?a=1" - i.e. it has lost the &b=2 part of the parameter. This seems to be asp.net stripping off the &b=2 bit - how can I get the whole parm value passed into my web method?
Thanks very much!
Are you absolutely certain that you are urlencoding the value before placing it in the query string? The query string parser splits on the '&' sign, which should be %26 after it is url encoded. If it remains as an '&' character, it will cause the query string parser to b=2 is another name value pair in the outer query string. I'd take a closer look at what you are sending.
You should see something like this: hlink=a.apsx%3Fa%3D1%26b%3D2

Resources