How can I access the member variable of an object by using a variable in the name.
Example:
Entries Object has properties 1, 2, 3, 4, 5.
Normally I would access them by
var i : int = Entries.1;
var i : int = Entries.2;
However, if I have a loop
for (var j : int = 1; j < 6; j++){
trace(Entries[j]);
}
does not work.
Entries.(j)
Entries.j
neither.
What's the way to go?
Entries.hasOwnProperty("j")
also does not work to check if the member exists.
Thanks!
Entries.hasOwnProperty("j")
does not work because you're sending it "j" as a string, you need to convert the integer variable j to a string, therefore representing the number you are looking for. Eg:
Entries.hasOwnProperty(j.toString());
So to extract the property from your object, you can do:
for(var j:int = 1; j < 6; j++)
{
trace(Entries[j.toString()]);
}
Related
In javaFx, treetableView, we can hide or show columns using "+" i.e
setTableMenuButtonVisible(true) symbol
say I have 10 columns in treetableview, but i have shown only 5, How can my program get count of only those columns which are visible (i.e 5 in this case)
U can have something like
ObservableList<TableColumn> visibleColumnList =FXCollections.observableArrayList();
ObservableList<TableColumn > tableColumnList = tableView.getColumns();
for (int j = 0; j < tableColumnList.size(); j++) {
TableColumn tableCol = tableColumnList.get(j);
if (tableCol.isVisible())
visibleColumnList.add(tableCol);
}
Long count = visibleColumnList.size();
Thanks Dev for your answer, though tableCol.isVisible method doesnt works for me, but i got it done other way round.
int count=0;
for (int j = 0; j < ltpSystemViewer.getTable().getColumnCount(); j++) {
TableColumn tableCol = ltpSystemViewer.getTable().getColumn(j);
if (tableCol.getWidth()>0)
count++;
}
return count;
I am doing some Hacker Rank problems and I cannot figure out what the encryption method is in the challenge details, here is the challenge.
Excerpt from the challenge:
The encoded message is obtained by displaying the characters in a column, inserting a space, and then displaying the next column and inserting a space, and so on. For example, the encoded message for the above rectangle is:
imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau
There is no mention of how the characters are changed to the output example the challenge provides...
I understand all elements of this question I think. The problem for me is: there is no details in the challenge about, after storing text in a grid, how the letters are encrypted.
Perhaps I am just very unfamiliar with encryption techniques and if I was more versed I could recognize some simple encryption pattern from the example output.
What am I missing here?
Just read it like this (concatenate marked letters):
imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau
Then go back at the beginning and take the second letter from each word and so on.
IfManWas MeantToS ...
The approach as described in the problem, is to remove spaces and make a hole string. Then calculate the rows and cols and create a matrix multidimensional arre. Go through the string storing the chars in the matrix. Then reverse the matrix and create the final string.
static String encryption(String s) {
String S = s.replace(" ", "");
int L = S.length();
int tryRow = (int) Math.floor(Math.sqrt(L));
int row;
int col = (int) Math.ceil(Math.sqrt(L));
if (tryRow * col < L) {
row = tryRow + 1;
} else {
row = tryRow;
}
char[][] matrix = IntStream.range(0, L).collect(
() -> new char[row][col],
(acc, i) -> {
int r = i / col;
int c = i - (r * col);
acc[r][c] = S.charAt(i);
},
(a, b) -> {
});
char[][] temp = new char[col][row];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
temp[j][i] = matrix[i][j];
}
}
return Arrays.stream(temp)
.map(arr -> String.valueOf(arr).trim())
.collect(Collectors.joining(" "));
}
I need to get a list of all display methods in a table, and I can't seem to find anything about this on the web.
Anyone know how to do this?
On display methods displayType is set to DisplayFunctionType::Get.
DictTable dt = new DictTable(tableNum(VendTable));
DictMethod dm;
DisplayFunctionType dft;
DictType dEdt;
int mtdCnt = dt.objectMethodCnt();
int i;
setPrefix(strFmt("Table: %1", dt.name()));
for (i = 1; i <= mtdCnt; i++)
{
dm = dt.objectMethodObject(i);
dft = dm.displayType();
if (dft == DisplayFunctionType::Get)
{
dEdt = new DictType(dm.returnId());
info(strFmt("Method: %1 (Label: %2)", dm.name(), dEdt.label()));
}
}
Hi
i am creating online quiz. For that i am creating arrays of answers selected by user. i used following code for that, it gives correct array but sometimes gives error "Index was outside the range"
//rsel is session values for selected answer
int rsel = Convert.ToInt32(Session["rblsel"]);
// [Convert.ToInt32(Session["Counter"] indicates size of array of no. of questions
int[] ansarray = new int[Convert.ToInt32(Session["Counter"]) - 1];
int[] temp = (int[])Session["arrofans"];
int j,n;
if (temp == null)
n = 0;
else
n = temp.Length;
for (j = 0; j < n; j++)
{
ansarray[j] = temp[j];
}
ansarray[j] = rsel;
Session["arrofans"] = ansarray;
Help me to find out exact error. Asp.net,c#
Thank you.
Why are you reducing the "counter" by one?
int[] ansarray = new int[Convert.ToInt32(Session["Counter"]) - 1];
It looks like that should probably be a + 1... but to be honest it would be simpler to use the size of ansarray - and use Array.Resize to effectively extend it:
int[] ansarray = (int[])Session["arrofans"];
Array.Resize(ref ansarray, ansarray.Length + 1);
ansarray[ansarray.Length - 1] = rsel;
Session["arrofans"] = ansarray;
That way you don't even need the "Counter" part of the session.
One possible OutOfRange could be triggered when
**arrofans.length >= Counter**
temp.Length should not be bigger than ansarray.Length, or precisely from your code it ansarray.Length must be temp.Length+1 or bigger. To avoid your problem you must change it to for (j = 0; j < n && j < (ansarray.Length-1); j++) but i don't know if it will suite your case
What is the most efficient way to insert one Vector into another at specific position?
For example:
var aa:Vector.<int> = Vector.<int>([1, 2, 3]);
var bb:Vector.<int> = Vector.<int>([9, 8, 7]);
This doesn't seems to work:
bb.splice(1, 0, aa);
The result is [9, 0, 8, 7].
For the moment there is no builtin function other than doing a loop over the Vector, here two methods (i have not timed them).
If bb can be a new Vector you can do for example:
var insertIndex:int = 1;
bb=bb.slice(0, insertIndex).concat(aa).concat(bb.slice(insertIndex));
If bb cannot be change you can do a splice but with preparing the elements to insert into a new Array:
var insertIndex:int = 1;
var parms:Array=[insertIndex, 0]; // prepare the arguments for the splice call
var j:int = 2; // length of the parms array
var len:int = aa.length;
for (var i:int = 0; i < len; i++, j++){
parms[j] = aa[i];
}
// call the splice with the new arguments
bb.splice.apply(bb, parms);
If you need to concat one after the other, as PatrickS mentionned bb.concat will do the job.
If you need to insert values in the middle you'll need something like
for each (var i : int in aa.reverse())
{
bb.splice(1,0,i);
}
or, more elegantly, this, if you cannot change aa
var insertingIndex : int = 2;
for each ( var i : int in aa )
{
bb.splice( insertingIndex, 0, i );
insertingIndex++;
}