Set timeVc=timeVw.Allentries
Set tobeDeleted=timeVw.Getalldocumentsbykey("", true)
Call tobeDeleted.removeall(True)
Just now want to confirm what is the meaning of getalldocumentbykey with empty string
GetAllDocumentsByKey with an empty string as first parameter returns an empty collection.
If you want to get all documents with an empty value in view's first sorted column then change the formula of your first sorted column to
#If(YourFieldName = ""; " "; YourFieldName)
It has a space instead of an empty string now.
Set tobeDeleted=timeVw.Getalldocumentsbykey(" ", true)
returns all those documents then.
Related
A scenario where the variable tempMID of type string containing value "338715618884", checks if it contains "" or not. It is returning true. Why is this happening? in my understanding, this shouldn't return true.
That's documented:
String.Contains returns true if the value parameter occurs within
this string, or if value is the empty string (""); otherwise, false.
So it's working as expected. The language designer have decided that an empty string is contained in every existing string, which makes sense to me.
If I have a string for example:
"this.is.a.string.and.I.need.the.last.part"
I am trying to get the last part of the string after the last ".", which in this case is "part"
How to I achieve this?
One way I tried was to split the string on ".", I get a array back, but then I don't know how to retrieve the last item in the array.
| extend ToSplitstring = split("this.is.a.string.and.I.need.the.last.part", ".")
gives me:
["this", "is","a","string","and","I","need","the","last", "part"]
and a second try I have tried this:
| extend ToSubstring = substring(myString, lastindexof(myString, ".")+1)
but Kusto do not have a function of lastindexof.
Anyone with tips?
you can access the last member of the array using a negative index -1.
e.g. this:
print split("this.is.a.string.and.I.need.the.last.part", ".")[-1]
returns a single table, with a single column and a single record, with the value part
You can try the code below, and feel free to change it to meet your need:
let lastIndexof = (input:string, lookup: string) {
indexof(input, lookup, 0, -1, countof(input,lookup))
};
your_table_name
| extend ToSubstring = substring("this.is.a.string.and.I.need.the.last.part", lastIndexof("this.is.a.string.and.I.need.the.last.part", ".")+1)
To query empty fields I have seen this answer:
Postgresql, select empty fields
(unfortunately I don't have enough reputation points to answer #wildplasser on that post, so here we go)
Wildplasser's answer:
SELECT mystr, mystr1
FROM mytable
WHERE COALESCE(mystr, '') = ''
OR COALESCE(mystr1, '') = ''
;
I am not sure I get the COALESCE method, but it also works for me this way (specific for my string data type):
SELECT mystr, mystr1
FROM mytable
WHERE mystr = '' ;
My questions are:
Does COALESCE work for any data type?
Is there any better way to query empty strings? i.e., column_value = ' '
First you need to understand the difference between NULL and "empty".
NULL is the absence of a value. Any (or at least almost any) data type can be NULL. When you have a column of type integer, and you don't want to put a value in that field, you put NULL.
"Empty" is a string/text concept. It's a string with an empty value, i.e. ''. A text field with an empty string contains a value: the empty string. It is not the same as containing NULL, i.e. no value. Other data types e.g. integer, boolean, json, whatever, can't have an empty string.
Now to COALESCE. That function works on any data type, and basically it returns the first not-NULL result of its arguments. So COALESCE(NULL, TRUE) returns TRUE because the first argument is NULL; COALESCE(FALSE, TRUE) returns FALSE because the first argument is not NULL; and COALESCE(NULL, NULL) returns NULL because there are no not-NULL arguments.
So, COALESCE(field, '') returns the value of field if it's not NULL, and otherwise returns an empty string. When used in COALESCE(field, '') = '' when trying to find any rows where field is "empty", this is basically saying "if field is NULL then use an empty string in its place, then see if it equals an empty string". This is because NULL and an empty string are not equivalent, and "you" are trying to find any rows where fields are NULL or empty.
In your version of the query, where you just do field = '', that will ONLY return results where field is actually an empty string, not where field is NULL. Which behaviour you desire is up to you.
With COALESCE you will get NULL values too in the first query.
1- In Postgresql, you can't mix datatype example here, but you can use the function to_char to mix values
2- I don't understand your question
I think based on the definition of coalesce itself as
"The COALESCE() function returns the first non-null value in a list."
means that it work for any data type
I don't really understand the question but i think yes its already the most efficient way to make empty string
I would like to read an excel file (xlsread) but I don't want to put manually the string every time but instead I want to xlsread the name of the file that is contained in an array.
For example, my array B is:
B =
'john.xlsx'
'mais.xlsx'
'car.xlsx'
Then I would like to read the excel WITH THE NAME that is inside the first element, that means: "john.xlsx"
How can I do this?
data = xlsread(B{1});
Or, if you want to read all of them:
for i=1:length(B)
data(i).nums = xlsread(B{i});
end
Assuming, of course, your B is a cell array. If it's not, it can't exist the way you described it. If all strings have the same length (then it would be possible) or padding with spaces, you can split the char array into a cell array using
B = mat2cell(B,ones(size(B,1),1),size(B,2));
Strings of different lengths would have to be inside a cell array, which you can access elements via the curly brackets {}. So, you can call xlsread on the first element this way:
names{1} = 'john.xlsx';
names{2} = 'mais.xlsx';
names{3} = 'car.xlsx';
num = xlsread(names{1});
If you set up a simple test form with a TextBox bound to a string property of a class and delete the content the value passed back to the property setter is "".
If you do the same thing with a cell in a DataGridView the value passed back to the property setter is Nothing.
Why the difference and is there anything we can apply to the DataGridView to make it behave the same as a TextBox?
if am correct the DataGridViewTextBoxCell by default is Null and the TextBox by Default is String.Empty
you might check the Null vs Empty
Nothing is VB's version of C#'s null or a database's NULL. It means that there is no value, as opposed to "" which means that there is a value, of an empty string.
I'm not entirely sure, but I suspect the difference is because a textbox's Text property is always a string, but a cell's Value property can be any object. You can use the null-coalescing operator to return an empty string when the value is Nothing.
Set(ByVal value As String)
_Surname = If(value, "")
End Set
Alternatively, you can validate the cell post-edit and set it to ""explicitly. see here for an example - instead of messaging the user, you'd just change the value.
DataGridView converts "" into Null during cell parsing.
If you handle CellParsing event and just set ParsingApplied, then no further parsing will be performed and the resulting value will remain "".