Why does my function only return 0 when searching through strings to find certain sub strings?
Tag : java , By : Mariamario
Date : March 29 2020, 07:55 AM
like below fixes the issue The point of this function is to search through the string to find substrings such that it starts with "foo" and ends in "bar". , Because this: s.substring(startCharacter, startCharacter + 2)
if (s.substring(startCharacter, startCharacter + 3).equals("bar"))
|
Powershell find common strings varying number of arrays
Date : March 29 2020, 07:55 AM
help you fix your problem This is easy. You say you have two-dimensional array $j and want to find all strings that exist in all elements of $j. You create a temporary "total intersection" array out of $j[0] then run foreach on $j and create an intersection into that temporary. At the end it'll only contain those elements that all of the columns contain. # $j is two-dimensional, and has unique elements
$t=$j[0]
$j | % {
$i=$_ #rename to avoid confusion
if ($i -ne $j[0]) { $t = $t|where {$i -contains $_}}
}
# $t now has your intersection
|
A PL/pgSQL function with varying return type (and varying inner query)
Tag : sql , By : kennystone
Date : March 29 2020, 07:55 AM
I hope this helps you . I have two comments to the first solution. First, use or %I or quote_ident() in format() function, not both. Compare: with q(s) as (
values ('abba'), ('ABBA')
)
select
quote_ident(s) ok1,
format('%I', s) ok2,
format('%I', quote_ident(s)) bad_idea
from q;
ok1 | ok2 | bad_idea
--------+--------+------------
abba | abba | abba
"ABBA" | "ABBA" | """ABBA"""
(2 rows)
create or replace function my_select(into_table text, tbl text, order_by text default null)
returns void as $function$
declare
q text;
begin
q := 'select * from ' || quote_ident(tbl);
if order_by is not null then
q := q || ' order by ' || order_by;
end if;
execute format($$
create temp table %I
on commit drop
as %s
$$, into_table, q);
end
$function$ language plpgsql;
begin;
select my_select('my_tmp', 'my_data1', 'id');
select * from my_tmp;
commit;
BEGIN
my_select
-----------
(1 row)
id | val
----+-----
1 | a
2 | c
3 | d
4 | b
(4 rows)
COMMIT
|
Python3: Is there a way to split a list of strings into separate lists, considering that the strings are of varying leng
Date : March 29 2020, 07:55 AM
Hope this helps For example: , Check this >>> list_string = ["This is a string that I want."
, "this is also a string that I want!"
, "and this"
, "and also this one!!"]
>>> [[i] for i in list_string]
[['This is a string that I want.'], ['this is also a string that I want!'], ['and this'], ['and also this one!!']]
>>>
|
How to disambiguate repeated strings by appending varying length strings?
Date : March 29 2020, 07:55 AM
hop of those help? We can take advantage of make.unique by striping the numbers that make the characters unique, and using them (... + 1) as reference as to how many characters to append, i.e. i1 <- as.numeric(gsub('\\D+', '', make.unique(x)))
i1[is.na(i1)] <- 0 #because where there is no number it returns NA
paste0(x, sapply(i1 + 1, function(i) paste(rep(' ', each = i), collapse = '')))
#[1] "a " "b " "c " "a " "b " "a " "c " "d " "e "
|