I have some method in which I want to display a sudoku grid, nothing fancy (it prints lines to the console). Here is the method:
public static void DisplaySudoku(){
System.out.println("=====================================");
for(int i = 0 ; i < 9 ; i++){
System.out.print("|");
for(int j = 0 ; j < 9 ; j++){
System.out.print(" " + String.valueOf(linesArray[i][j].charAt(2)) + " |" );
}
System.out.print("\r");
}
System.out.println("=====================================");
}
The array linesArray[][] is built somewhere else, and is actually working, stored in a member of the class (I have tested it, displaying values within the main method without any problem). But the output when compiling and running gives me only the top and bottom lines:
=====================================
=====================================
I wonder why it seems to skip everything inside the loops?
Got it, the \r returns to the beginning of the line without actually changing to a new line. Will try to work it out some other way.
Related
For following example codes
<div>
#for (int i = 0; i < 10; i++)
{
<span class="#classes[i]">#i</span>
}
</div>
What I want to display is (with each character in different style)
01234567890
but what actually display is (additional whitespace between each characters)
0 1 2 3 4 5 6 7 8 9
I use ILSpy to investigate what happens in the render tree, and found following
__builder.OpenElement(2, "div");
__builder.AddMarkupContent(3, "\r\n");
for (int i = 0; i < 10; i++)
{
__builder.AddContent(4, " ");
__builder.OpenElement(5, "span");
__builder.AddAttribute(6, "class", classes[i]);
__builder.AddContent(7, i);
__builder.CloseElement();
__builder.AddMarkupContent(8, "\r\n");
}
__builder.CloseElement();
The sequence 4 adds additional whitespaces and sequence 8 adds "\r\n", which I believe is the reason of the additional whitespace between characters.
I could mitigate the issue by writing in this way
<div>#for (int i = 0; i < 10; i++)
{<span class="#classes[i]">#i</span>}
</div>
However, when there are more and different contents in the same line, the code would be very long. Also when I press Ctrl+D to format the document, in some scenarios VS would "fix" the code in wrong way.
I would like to see if there's any better suggestion for this issue. I thought about following (but couldn't find solution yet)
Use CSS to ignore whitespaces and \r\n between spans
Somehow add extra #{} to help formatting.
Some magic parameter to avoid whitespaces and \r\n added to the render tree.
I guess you are still using aspnetcore 3.x, as this was fixed in .NET5.
Try it in a .NET5 Blazor project - it should work fine.
Attempting to loop through this array, stored in a JSON file. I want to be able to check if a quote is saved and then display it depending on whether it is saved or not.
_toggleCheck() {
var checked = !this.state.checked;
this.setState({ checked: checked });
// For loop to run through arrray and update booleans
for(int i = 0; i<quotesArray.length-1; i++;){
quotes.quotesArray[i].isSaved = checked;
}
this.props.onChange && this.props.onChange(this.props.name, checked);
}
In attempting to do this, I have come across this error and can not resolve it. Line 63 is the beginning of the for loop. I dont know how to use a for loop in react native and cant find any tutorials on line.
for(int i = 0; i<quotesArray.length-1; i++;){
^ remove this semicolon
By the way, are you sure you want i < quotesArray.length - 1 instead of i < quotesArray.length? You're skipping the last element when you add -1.
Inside a foreach loop i have a statement
#(var = var1 + var2 ) ;
the math occurs but the results var gets displayed on the page after each execution. I don't want that to happen just do the math so I can display results at the bottom of the table.
thanks
You need to remove the # symbol as when you're in your for each loop, you're already in a code block.
Your code should look a little like this:
#foreach (var i in a)
{
var x = i + i;
}
I Am adding the customized Clickable spans to my
MultiAutoCompleteTextview. After adding 2 or more Contacts in That
Edit Text. i am replacing the extra Spans to Image Span with Text
Contains Count . My problem is that count is displaying different in
lower end devices(i.e., 2.2) and higher end devices(i.e., 4.0). Please
have a look into the below Pictures.
Higher End Devices.
LOwer End Devices
So problem with Higher end devices. each extra chip is replacing the count 2 times.
Here is the code for replacing the extra chip PLease find it.
void createMoreChipPlainText() {
Editable text = getText();
int start = 0;
int end = start;
for (int i = 0; i < CHIP_LIMIT; i++) {
end = movePastTerminators(mTokenizer.findTokenEnd(text, start));
start = end; // move to the next token and get its end.
}
// Now, count total addresses.
start = 0;
int tokenCount = countTokens(text);
MoreImageSpan moreSpan = createMoreSpan(tokenCount - CHIP_LIMIT);
SpannableString chipText = new SpannableString(text.subSequence(end,
text.length()));
chipText.setSpan(moreSpan, 0, chipText.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
text.replace(end, text.length(), chipText);
mMoreChip = moreSpan;
}
Is there any issue with replace method for editable class in android. Any one have any idea about this issue. please post your suggestions here
I'm developing a simple Chrome extension, which should be able to retrieve a DOM nodes and modify them in the specific way. And this is what I'm stuck with.
There are two DOM queries (lets call the A and B) in a javascript file, that i inject in html-page. The first one (A) goes well, but the second one (B) always crushes. Even If I interchange the first (A) query and second one (B), everything will still work in the same way. Query (B) now works as it should in the first place, and A now does nothing.
spans = document.getElementsByTagName('span');
for(j =0 ;j<=divin.length; j++)
{
//Manipulations //Works just fine
}
paragraphs = document.getElementsByTagName('p');
for(j =0 ;j<=paragraphs.length; j++)
{
//Manipulations //Does nothing
}
And what we see here. The same code, but different position.
paragraphs = document.getElementsByTagName('p');
for(j =0 ;j<=paragraphs.length; j++)
{
//Manipulations //Works just fine
}
spans = document.getElementsByTagName('span');
for(j =0 ;j<=divin.length; j++)
{
//Manipulations //Does nothing
}
I tried every way of injecting this code, but result was always the same.
Seems like you're using divin.length instead of spans.length.