How to select a line of Result Console application - console-application

I have a Foreach loop:
Foreach(htmlnode node in SOMETHING)
{
var link = node.GetAttributeValue("href", "");
Console.WriteLine(link);
}
that loop shows a list of tags like:
http://ca1006761246.trustpass.alibaba.com/contactinfo.html
http://ca1006761246.trustpass.alibaba.com/contactinfo.html
http://ir100058530.trustpass.alibaba.com/contactinfo.html
http://ir100058530.trustpass.alibaba.com/contactinfo.html
http://tjyixuan.en.alibaba.com/contactinfo.html
http://tjyixuan.en.alibaba.com/contactinfo.html
http://alchemyfood.en.alibaba.com/contactinfo.html
http://alchemyfood.en.alibaba.com/contactinfo.html
http://wuhueasy.en.alibaba.com/contactinfo.html
How do I select and store each line separately like:
line1:http://ca1006761246.trustpass.alibaba.com/conta
How to Focouse on result of consoleApplication Program

Related

Google Script - Removing Else statement properly so it skips/ignores

I have a checklist, column C indicates which test is automated by "enabled" or "disabled" written in the cells.
Further down the row is a column for the the Pass / Empty column for each test.
I have code that looks for if Enabled in column C, in X column on that row, mark as Pass automatically (or 'P' in my case).
The problem: If C column contains "Disabled" but also a Pass, when I run the script it replaces that Pass with an empty cell. How can I change the else statement to just ignore that cell and leave whatever is in it for anything but Enabled condition is met
function autoPassPC() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Aug 2020');
// What to put in the test result
var values1 = "P";
// Where to look for Auto:
var values2 = sheet.getRange("C10:C15" + sheet.getLastRow()).getValues();
// Keyword to look for in Auto: column
var putValues = [];
for (var i = 0; i < values2.length; i++) {
if (values2[i][0] === "Enabled") {
putValues.push([values1]);
} else {
putValues.push([""]);
}
}
// Put value1 inside row, column# for test result
sheet.getRange(10, 25, putValues.length, 1).setValues(putValues);
}
Basically how do I get rid of
} else {
putValues.push([""]);
}
properly? Just deleting this causes the script to put 'P' on every single row. Just want it to ignore the cells instead.
Thanks!
Removing the else statement will actually skip the row, but as soon as you skip a row, all following values in putValues will be on the wrong row. Instead of "skipping", try pushing the already existing value into putValues.
function autoPassPC() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Aug 2020');
// What to put in the test result
var values1 = "P";
// Where to look for Auto:
var enabledDisabled = sheet.getRange("C10:C15" + sheet.getLastRow()).getValues();
var testResultsRange = sheet.getRange("X10:X15" + sheet.getLastRow());
var testResults = testResultsRange.getValues();
// Keyword to look for in Auto: column
var putValues = [];
for (var i = 0; i < enabledDisabled.length; i++) {
if (enabledDisabled[i][0] === "Enabled") {
putValues.push([values1]);
} else {
putValues.push([testResults[i][0]]); // Push the existing cell value
}
}
// Put value1 inside row, column# for test result
testResultsRange.setValues(putValues);
}
You could also try getting the entire table at once thus having only one getValues() call.

This "IF" won't work for me. Why?

I have written the following code:
function test() {
var spreadsheet = SpreadsheetApp.getActive();
var ui = SpreadsheetApp.getUi();
var testModeStatus = spreadsheet.getSheetByName("Students").getRange("P2:P2").getValues();
if (testModeStatus == 'FALSE') {
ui.alert("This is inside IF and Test Mode Status is "+testModeStatus);
};
ui.alert("This is outside IF and Test Mode Status is "+testModeStatus);
};
In the above code the variable testModeStatus refers to a sheet cell that is a checkbox and can have the value of either TRUE(checked) or FALSE(unchecked).
I want the code inside if to run only when the checkbox is unchecked. But no matter if the checkbox is checked or unchecked, the code inside if never runs and in both cases just the code outside if runs.
Moreover, in both cases the variable testModeStatus shows the correct value in the popping alert message. I mean if the checkbox is checked the variable shows TRUE and if it is unchecked the variable shows FALSE in the popping alert message.
you're comparing apples with oranges
.getValues() returns a bi-dimensional array and "FALSE" is a string.
Since you get a cell, you can use .getValue instead, but do note that GAS parses the boolean into a JS boolean, so, ultimately, the code should be:
function test() {
var spreadsheet = SpreadsheetApp.getActive();
var ui = SpreadsheetApp.getUi();
var testModeStatus = spreadsheet.getSheetByName("Students").getRange("P2:P2").getValue(); // getValue, not values
if (testModeStatus == false) { //false, not "FALSE"
ui.alert("This is inside IF and Test Mode Status is "+testModeStatus);
};
ui.alert("This is outside IF and Test Mode Status is "+testModeStatus);
};

Using Roslyn, how to enumerate members (Namespaces, classes etc) details in Visual Basic Document?

Using Roslyn, the only mechanism for determining members of Visual Basic document appears to be:
var members = SyntaxTree.GetRoot().DescendantNodes().Where(node =>
node is ClassStatementSyntax ||
node is FunctionAggregationSyntax ||
node is IncompleteMemberSyntax ||
node is MethodBaseSyntax ||
node is ModuleStatementSyntax ||
node is NamespaceStatementSyntax ||
node is PropertyStatementSyntax ||
node is SubNewStatementSyntax
);
How do get the member name, StarLineNumber and EndLineNumber of each member?
Exists not only the one way to get it:
1) As you try: I willn't show this way for all of kind member (they count are huge and the logic is the similar), but only a one of them, for example ClassStatementSyntax:
to achive it name just get ClassStatementSyntax.Identifier.ValueText
to get start line you can use Location as one of ways:
var location = Location.Create(SyntaxTree, ClassStatementSyntax.Identifier.Span);
var startLine = location.GetLineSpan().StartLinePosition.Line;
logic for retrieving the end line looks like a logic to receive the start line but it dependents on the corresponding closing statement (some kind of end statement or self)
2) More useful way – use SemanticModel to get a data that you want:
In this way you will need to receive semantic info only for ClassStatementSyntax, ModuleStatementSyntxt and NamespaceStatementSyntax, and all of their members will be received just calling GetMembers():
...
SemanticModel semanticModel = // usually it is received from the corresponding compilation
var typeSyntax = // ClassStatementSyntax, ModuleStatementSyntxt or NamespaceStatementSyntax
string name = null;
int startLine;
int endLine;
var info = semanticModel.GetSymbolInfo(typeSyntax);
if (info.Symbol is INamespaceOrTypeSymbol typeSymbol)
{
name = typeSymbol.Name; // retrieve Name
startLine = semanticModel.SyntaxTree.GetLineSpan(typeSymbol.DeclaringSyntaxReferences[0].Span).StartLinePosition.Line; //retrieve start line
endLine = semanticModel.SyntaxTree.GetLineSpan(typeSymbol.DeclaringSyntaxReferences[0].Span).EndLinePosition.Line; //retrieve end line
foreach (var item in typeSymbol.GetMembers())
{
// do the same logic for retrieving name and lines for all others members without calling GetMembers()
}
}
else if (semanticModel.GetDeclaredSymbol(typeSyntax) is INamespaceOrTypeSymbol typeSymbol2)
{
name = typeSymbol2.Name; // retrieve Name
startLine = semanticModel.SyntaxTree.GetLineSpan(typeSymbol2.DeclaringSyntaxReferences[0].Span).StartLinePosition.Line; //retrieve start line
endLine = semanticModel.SyntaxTree.GetLineSpan(typeSymbol2.DeclaringSyntaxReferences[0].Span).EndLinePosition.Line; //retrieve end line
foreach (var item in typeSymbol2.GetMembers())
{
// do the same logic for retrieving name and lines for all others members without calling GetMembers()
}
}
But attention, when you have a partial declaration your DeclaringSyntaxReferences will have a couple items, so you need to filter SyntaxReference by your current SyntaxTree

How to create list from another typed list with 'List.from'?

Simple dart code:
class User {
String name;
User(this.name);
}
main() {
List<User> users = [new User('Freewind')];
var list = new List.from(users);
print(list.first.name); // ***
}
Notice the line ends with '// *'.
My IDEA editor doesn't recognize list.first as a User, since it can't do the autocompletion when I typed '.name'.
So I have to declare the type:
List<User> list = new List.from(users);
It works but I want to know if there is any other way to let compiler know list has type List<User>?
I tried:
var list = new List<User>.from(users);
Which has wrong syntax.
This one works for me in DartEditor (no error/warning/hint) and of course executes successfully
var list = new List<User>.from(users);

Linq query not matching hrefs

I'm trying to write out all matches found using a regex with the code below:
var source = "<Content><link><a xlink:href=\"tcm:363-48948\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">Read more</a></link><links xlink:href=\"tcm:362-65596\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"/></Content>";
var tridionHref = new Regex("tcm:([^\"]*)");
var elem = XElement.Parse(source);
XNamespace xlink = "http://www.w3.org/1999/xlink";
if (tridionHref.IsMatch(elem.ToString()))
{
foreach (var Id in elem.Elements().Where(x => x.Attribute(xlink + "href") != null))
{
Console.WriteLine(Id.Attribute(xlink + "href").Value); //For testing
Id.Attribute(xlink + "href").Value = Id.Attribute(xlink + "href").Value.Replace("value1", "value2"); //Just to show you an example
}
}
My console window outputs tcm:362-65596 but not tcm:363-48948. It looks like the code doesn't see the value of xlink:href inside my <a> tag as an attribute? Can anyone point me in the right direction? I need to match ALL instances of tcm:([^\"]*).
The problem is you are not looking in the right place. Your elem.Elements is looking at the link element and the links element. Only one of these has the attribute that you are looking for. You'll need to select the elements you want to check more precisely before looking for the right attribute.
I've got it working. I didn't need a regex I just needed to get the Descendants instead inside my for loop. foreach (var Id in elem.Descendants().Where(x => x.Attribute(xlink + "href") != null))