How to count occurrences of a character in a string in Presto? - presto

I am trying to find the number of frequency of a character in a string in Presto.
like 129.11.20.0 and I wan to find number of dot . in this string.
just wondering if any function available

I was looking for the same in AWS athena, which is a managed presto service. It doesn't support regexp_count, so I used the following expression instead:
SELECT CARDINALITY(REGEXP_EXTRACT_ALL('1.1.1.1', '\.'))

You can use regexp_count function.

Related

Regex or IndexOf?

I have a long string "AB100123485;AB10064279293-IP-1-KNPO;AB473898487-MM41". I have to extract integer value after "IP-" i.e 1 (only) what is the most efficient way ? I am using c#
Thanks
The 'most-efficient' way depends on how consistent your string is in terms of length and appearance. You can surely do this with a regular expression as a quick solution if you just want to get the digit directly following IP-.
You can utilize the RegularExpressions API, passing in your regular expression and input string.
https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.match?view=netframework-4.8#System_Text_RegularExpressions_Regex_Match_System_String_System_String_
This pattern should get you started IP-[0-9]; refine it more to your use case as needed.
For example:
Match matched = System.Text.RegularExpressions.Match(
"AB100123485;AB10064279293-IP-1-KNPO;AB473898487-MM41",
"IP-[0-9]"
);

Substr - Instr Function Error in Power BI

I used the SEARCH function in Power BI but finds the location of the character I want to find incorrect.
The screenshot will tell you better.
Actually, I want to extract source system (android - ios etc). Essentially I can do with SQL using instr - substr but I want to use DAX Language.
Please help.
I tried to reproduce this. I had to change the semicolon to a comma to separate the arguments.
You can use MID to return substrings, which takes the start position and length as arguments.
=var str_start = search("Twitter for",[source])
var str_end = search("</a>",[source])
return mid([source],str_start, str_end-str_start)

Wildcard search for LINQ to SQL

I want to do a wildcard search using LINQ to SQL.
using Contains, StartsWith, EndsWith only.
(not "SqlMethods.Like" method)
the wild cards operate with two type of jokers:
? - any character (one and only one)
* - any characters (zero or more)
Is there a way to do this?
Regards
No it isn't possible. If you have both ? and * in your matching expression, there is no way to convert the ?.
Also, to convert ? by itself would require using Length.

How to use reserved words in Azure Search Filter?

I am using Azure Search Filter option like follows
$filter=cityList/any(t: search.in(t, '1')) and name eq 'hi tech bar & restaurant' &search=*&scoringProfile=search-score&searchMode=Any&queryType=FULL
For all word filters except reserved words are working fine.
; / ? : # = + &
Can anyone help me to find how to use reserved words in Azure Search Filters ??
Thanks in advance.
There are two levels of encoding to consider. First, the OData expression itself. I'm assuming you need to use the special characters in a string constant, in which case the only character you need to encode is single quote, which you can encode by doubling. For example: $filter=Name eq 'O''Neil'. The second level of encoding depends on whether you're using HTTP GET or POST for your search request. If you're using the Azure Search .NET SDK, it takes care of this detail for you. If you're using the REST API directly and you're using GET, you need to URL encode the filter expression. If you're using POST, you need to encode the filter expression as you would any other JSON string. For example, you need to encode \ as \ and " as \", etc. Hope this helps.

String functions in Sybase ASE

I want to retrieve "name" from "My_name_is_ABC", how to do it in Sybase-ASE ?
I tried finding on internet but inbuild functions i saw are not supported in ase.
Atleast i need to know how to do find index of a string.
Sybase ASE does have inbuilt string functions as Documented Here. You can use SUBSTRING and CHARINDEX function to get your desired result like below
select substring("My_name_is_ABC",charindex("_", "My_name_is_ABC")+1,4)
Syntax for Substring function : substring(expression, start, length )
select substr('My_name_is_ABC',locate('My_name_is_ABC','name'),4) from dummy

Resources