asp.net array / arraylist error - asp.net

I'm working on something relatively simple (or so I thought) and need a bit of help.
I am trying to create a dynamic amount of comma separated strings.
I have a variable (numberOfStrings) which is the number of different strings I need.
I just want to loop thru the aryDrivers and assign then to the different strings.
Dim aryHeats(numberOfStrings - 1) As ArrayList
Dim aryDrivers() As String
aryDrivers = txtBatch.Text.Split(",")
For i As Integer = 0 To aryDrivers.Length - 1
For j As Integer = 0 To aryHeats.Length - 1
aryHeats(j).Add(aryDrivers(i) & ",")
Next
Next
For some reason I'm getting an error in the loop when I try to "ADD" the string.
Thoughts?
Thanks!
** Update **
Maybe this will help explain more what I'm trying to do.
I have a string:
s = A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
i'm passing a variable (numberOfHeats) lets use 4.
i would like to then have 4 strings (so I am wanted to use array)
ary(0) = A,E,I,M,Q,U,Y
ary(1) = B,F,J,N,R,V,Z
ary(2) = C,G,K,O,S,W
ary(3) = D,H,L,P,T,X
hopefully that clears this up.

You could use LINQ, although i hate VB.NET method syntax:
Dim text = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
Dim numberOfHeats = 4
Dim aryHeats As String()() = s.Split(","c).
Select(Function(w, index) New With {.Word = w, .Index = index}).
GroupBy(Function(x) x.Index Mod numberOfHeats).
Select(Function(grp) grp.Select(Function(x) x.Word).ToArray()).
ToArray()
Explanation: it takes the initial string and split it in words (comma as separator). Then it transforms the word and the according index in the String-Array to an anonymous type with Word and Index as properties. This list will be grouped by Index Mod numberOfHeats(the number of arrays you want). This implicitely orders by your desired result. The last step is to transform the groups to a jagged array.
Result:
(0)
(0) "A"
(1) "E"
(2) "I"
(3) "M"
(4) "Q"
(5) "U"
(6) "Y"
(1)
(0) "B"
(1) "F"
(2) "J"
(3) "N"
(4) "R"
(5) "V"
(6) "Z"
(2)
(0) "C"
(1) "G"
(2) "K"
(3) "O"
(4) "S"
(5) "W"
(3)
(0) "D"
(1) "H"
(2) "L"
(3) "P"
(4) "T"
(5) "X"

Try this
Dim aryHeats(numberOfStrings - 1) As ArrayList
Dim aryDrivers() As String
aryDrivers = txtBatch.Text.Split(",")
For i As Integer = 0 To aryDrivers.Length - 1
aryHeats( i Mod aryHeats.Length ).Add(aryDrivers(i) & ",")
Next

Related

Tracing a recursive function for longest common substring

I am getting confused tracing the following recursive approach to find the longest common substring. The last two lines are where my confusion is. Specifically how is the count variable getting the answer when characters of both string matches? In the last line which "count" does this refer to i.e count in the function definition or the updated count from function call? Are there any resources for better understanding of recursions?
int recursive_substr(string a, string b, int m, int n,int count){
if (m == -1 || n == -1) return count;
if (a[m] == b[n]) {
count = recursive_substr(a,b,m-1,n-1,++count);
}
return max(count,max(recursive_substr(a,b,m,n-1,0),recursive_substr(a,b,m-1,n,0)));
}
The first thing to understand is what values to use for the parameters the very first time you call the function.
Consider the two following strings:
std::string a = "helloabc";
std::string b = "hello!abc";
To figure out the length of the longest common substring, you can call the function this way:
int length = recursive_substr(a, b, a.length()-1, b.length()-1, 0);
So, m begins as the index of the last character in a, and n begins as the index of the last character in b. count begins as 0.
During execution, m represents the index of the current character in a, n represents the index of the current character in b, and count represents the length of the current common substring.
Now imagine we're in the middle of the execution, with m=4 and n=5 and count=3.
We're there:
a= "helloabc"
^m
b="hello!abc" count=3
^n
We just saw the common substring "abc", which has length 3, and that is why count=3. Now, we notice that a[m] == 'o' != '!' == b[n]. So, we know that we can't extend the common substring "abc" into a longer common substring. We make a note that we have found a common substring of length 3, and we start looking for another common substring between "hello" and "hello!". Since 'o' and '!' are different, we know that we should exclude at least one of the two. But we don't know which one. So, we make two recursive calls:
count1 = recursive_substr(a,b,m,n-1,0); // length of longest common substring between "hello" and "hello"
count2 = recursive_substr(a,b,m-1,n,0); // length of longest common substring between "hell" and "hello!"
Then, we return the maximum of the three lengths we've collected:
the length count==3 of the previous common substring "abc" we had found;
the length count1==5 of the longest common substring between "hello" and "hello";
the length count2==4 of the longest common substring between "hell" and "hello!".

How does Firestore query operation strings treat different data types?

How does the Firestore opStr (Operation Strings) in the where query method treat different data types?
The different operation strings are: <, <=, ==, >, and >=
For number data type it is very self explanatory, but how about for the other data types? string, boolean, object, array, null, timestamp, geopoint, and reference
So for e.g. string data type, does >= mean is equal to or contains string?
So db.collection('users').where('lastname','>=','bar') would return all users that has a lastname of bar or contains bar? e.g. bar, foobar, barbaz
Does anyone know of any documentation for this specific subject?
For string types, the >= evaluates based on the lexicographical ordering of the values.
Some examples:
"a" < "b"
"aaa" < "aab"
"abc" < "abcd"
And also:
"000" < "001"
"010" < "011"
"100" < "101"
But for example:
"2" > "10"
Since the "2" is alphabetically later than the "1" in unicode.

Cypher conditions on all nodes in collection behaving incorrectly?

I have this database:
CREATE (A:A {name:"A"})-[:R]->(B:B {name:"B"})-[:R]->(C:B {name:"C"})-[:R]->(D:A {name:"D"})-[:R]->(E:A {name:"E"})
This query
MATCH p = (:A)-[*]->(:B) WITH NODES(p)[1..] AS p_nodes RETURN p_nodes
returns edge (B)-->(C). And B and C have both label B. Why then does this query
MATCH p = (:A)-[*]->(:B) WITH NODES(p)[1..] AS p_nodes
WHERE ALL(x IN p_nodes[0..] WHERE LABELS(x) = "B") RETURN p_nodes
return nothing (no rows)? The only thing it does is make sure that p_nodes contains B labeled nodes only. And as the first query showed it does.
The labels(x) function will return a collection of strings, not a string. This is because nodes can have multiple labels.
So instead of comparing labels(x) = "B" use the IN operator "B" in labels(x):
MATCH p =(:A)-[*]->(:B)
WITH NODES(p)[1..] AS p_nodes
WHERE ALL (x IN p_nodes[0..]
WHERE "B" IN LABELS(x))
RETURN p_nodes

Vb script string comparison error

I have tried all but its not working
I am getting a colum value form Data base as
substatus=rsprefobj("isnotificationactive");
after doing
Response.write substatus
It gives me --> n
and when i do
intcomaprestringval=StrComp(substatus,"n",vbTextCompare)
Response.write intcomaprestringval
It(intcomaprestringval) gives me --> 1 even though they are same
I want to take some decision based on database value if its "n" or "y"
If intcomaprestringval = 0 Then
some
Else
some
End If
But StrComp()always returns 1 in my case whether database value is "n" or "y" :(
I write a compare function that will return either "OK" if 2 values are a match or "No Match" if they do not. Here it is:
Function Compare(str1, str2, comp)
str = "OK"
If StrComp(str1, str2, comp) <> 0 Then str = "No Match"
Compare = str
End Function
str1 and str2 are the 2 values you wish to compare and comp is the method of comparison (0 = binary comparison and 1 = text comparison). I always use 0.
So you would use it like this:
If Compare(substatus, "n", 0) = "OK" Then
' Values match
Else
'Values do not match
End If
Hope it helps
Regarding your test:
intcomaprestringval=StrComp(substatus,"n",vbTextCompare)
Are you setting vbTextCompare to be 0 at some point earlier in your code?
I have used Trim() as suggested by #EntBark
Dim myvalue
myvalue=Trim(substatus)
intcomaprestringval=StrComp(myvalue,"n",vbTextCompare)

How to find original values back from the final result output of the sequential Xor procedures?

The problem is that I want to get the original values of B, or the original value of C or A. Here is the code:
Dim strA As String = "A"
Dim strB As String = "B"
Dim strC As String = "C"
Dim result As Byte = 0
' Fetch the byte character code of strings and Xor them all into the result in a sequence.
result = result Xor AscW(strA)
result = result Xor AscW(strB)
result = result Xor AscW(strC)
' the final result value is 64
How to do this? Please help me with the correct solution to this problem. If there can be another parameter which when applied with a formula may reveal the original values: "A", "B", "C". Thank you.
If I understand your question correctly, this is simply not possible. There are multiple ways to split result back into strA, strB and strC.
To make it easier to see why, consider addition instead. Suppose you start with A = 5, B = 6 and C = 7. The sum is 18. Now suppose you start with A = 1, B = 1 and C = 16. The sum is still 18. Bottom line: if all you have is "18" there's no way to split it back, because multiple inputs give the same output.

Resources