maybe that's a simple question, but I'm wondering, if the following lines will have the same result every time or if it's possible that there are differences.
string assemblyName = anyType.Assembly.FullName.Split(',')[0] + ".dll";
string assemblyName = anyType.Assembly.ManifestModule.Name;
As the first line is executed 150.000 times on startup of our application, there will be many allocations of string. I want to reduce that by the second line, but I'm not sure if it will be the same in every case.
Related
I have to verify text that present on web page but in the text line have dynamic wording that I don't know how to verify this situation.
Wait Until Element Contains &{verScript}[Script] Test automate for 50,000 time timeout=60s
I want to verify text "Test automate for 50,000 time" but 50,000 is dynamic value. I don't want to verify 50,000 in this locator and can it whatever for this value in line.
Can any help me please.
using set
#{queryResultsA}= split string Test automate for 50,000 time
#{queryResultsB}= split string Test automate for XX,XXX time
${z} = Evaluate (set(${queryResultsA}) - set(${queryResultsB}))
## here ${z} will be 50,000
Using keyword
will return all lines on the page which are matching given string. the following keyword will return Lines as one string concatenated back together with newlines
Get Lines Containing String Test automate for
for more keywords
which match partial and full text/strings
using regex and pattern matching
Consider the following string:
"><script>alert(1);</script>
I wish to assign this string (or a string like it) to an R variable.
If I try to do this the traditional way, such as:
x <- as.character("><script>alert(1);</script>)
the command fails due to the presence of the single quotation mark within the string itself. Is there a method to get round this complication without manipulating the string entirely?
It is important to keep the integrity of the string intact. For example, a method to get round this problem would be to change the quotation mark to an apostrophe, or to delete the quotation mark; but this is unacceptable.
Cheers
Is there a way to have a for loop like this where the loop hits the 60.1875? If I start the range at .1875 it will work but I can't do that in this case.
for a from 1 to 60.1875
next a
Edit: This code needs to test options for running a print job on different size papers. We prefer to test whole numbers but we always need to test the outer limit of the press as well which is 60.1875.
You need the Step keyword, or the loop will jump in steps of 1 only and will ignore non-integer values.
for example:
Dim start As Decimal = 1
Dim finish As Decimal = 60.1875
For i=start to finish Step 0.0005
If i = Int(i) Or i=start or i=finish Then
'... do whatever
End If
Next
Added the check for integers and outer bounds, but tbh this is cacked; there are better ways to do it!
My sugggestion would be to do something like:
dim limit as decimal = 60.1875
for a = 1 to limit
Console.WriteLine(a)
next a
Console.WriteLine(limit)
In your code of course replace Console.WriteLine with whatever code you are using.
My example above outputs the integers 1 to 60 and then 60.1875.
If you desperately need to run it in a single loop for some reason then you could use the above code to construct a List(of decimal) and then you could include everything in a single loop.
I am using the regular expression of the date for the format "MM/DD/YYYY" like
"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d$"
its working fine, no problem....here I want to limit the year between "1950" to "2050", how to do this, can anyone help me....
So the answer depends on how you want to accomplish the task.
Your current Regex search pattern is going to match on most dates in the format "MM/DD/YYYY" in the 20th and 21st century. So one approach is to loop through the resulting matches, which are represented as string values at this point, and parse each string into a DateTime. Then you can do some range validation checking.
(Note: I removed the beginning ^ and ending $ from your original to make my example work)
string input = "This is one date 07/04/1776 and this is another 12/07/1941. Today is 08/10/2019.";
string pattern = "(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\\d\\d";
List<DateTime> list = new List<DateTime>();
foreach (Match match in Regex.Matches(input, pattern))
{
Console.WriteLine(match.Value);
DateTime result;
if (DateTime.TryParse(match.Value, out result))
{
if (result.Year >= 1950 && result.Year <= 2050)
{
list.Add(result);
}
}
}
Console.WriteLine("Number of valid dates: {0}", list.Count);
This code outputs the following, noting that 1776 is not matched, the other two dates are, but only the last one is added to the list.
12/07/1941
08/10/2019
Number of valid dates: 1
Although this approach has some drawbacks, such as looping over the results a second time to try and do the range validation, there are some advantages as well.
The built-in DateTime methods in the framework are easier to deal with, rather than constantly adjusting the Regex search pattern as your acceptable range can move over time.
By range checking afterward, you could also simplify your Regex search pattern to be more inclusive, perhaps even getting all dates.
A simpler Regex search pattern is easier to maintain, and also makes clear the intent of the code. Regex can be confusing and tricky to decipher the meaning, especially for less experienced coders.
Complex Regex search patterns can introduce subtle bugs. Make sure you have good unit tests wrapped around your code.
Of course your other approach is to adjust the Regex search pattern so that you don't have to parse and check afterwards. In most cases this is going to be the best option. Your search pattern is not returning any values that are outside the range, so you don't have to loop or do any additional checking at that point. Just remember those unit tests!
As #skywalker pointed out in his answer, this pattern should work for you.
string pattern = "(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19[5-9][0-9]|20[0-4][0-9]|2050)";
year 1950-2050 both inclusive can be found using 19[5-9][0-9]|20[0-4][0-9]|2050
We have an automatic process that opens a template excel file, writes rows of data, and returns the file to the user. This process is usually fast, however I was recently asked to add a summary page with some Excel formulas to one of the templates, and now the process takes forever.
It successfully runs with about 5 records after a few minutes, however this week's record set is almost 400 rows and the longest I've let it run is about half an hour before cancelling it. Without the formulas, it only takes a few seconds to run.
Is there any known issues with writing rows to an Excel file that contains formulas? Or is there a way to tell Excel not to evaluate formulas until the file is opened by a user?
The formulas on the summary Sheet are these:
' Returns count of cells in column where data = Y
=COUNTIF(Sheet1!J15:Sheet1!J10000, "Y")
=COUNTIF(Sheet1!F15:Sheet1!F10000, "Y")
' Return sum of column where data is a number greater than 0
' Column contains formula calculating the difference in months between two dates
=SUMIF(Sheet1!I15:Sheet1!I10000,">0",Sheet1!I15:Sheet1!I10000)
' Returns a count of distinct values in a column
=SUMPRODUCT((Sheet1!D15:Sheet1!D10000<>"")/COUNTIF(Sheet1!D15:Sheet1!D10000,Sheet1!D15:Sheet1!D10000&""))
And the code that writes to excel looks something like this:
Dim xls as New Excel.Application()
Dim xlsBooks as Excel.Workbooks, xlsBook as Excel.Workbook
Dim xlsSheets as Excel.Sheets, xlsSheet as Excel.Worksheet
Dim xlsCells as Excel.Range
xls.Visible = False
xls.DisplayAlerts = False
xlsBooks = xls.Workbooks
xlsBooks.Open(templateFile)
xlsBook = xlsBooks.Item(1)
' Loop through excel Sheets. Some templates have multiple sheets.
For Each drSheet as DataRow in dtSheets.Rows
xlsSheets = xlsBook.Worksheets
xlsSheet = CType(xlsSheets.Item(drSheet("SheetName")), Excel.Worksheet)
xlsCells = xlsSheet.Cells
' Loop though Column list from Database. Each Template requires different columns
For Each drDataCols as DataRow in dtDataCols.Rows
' Loop though Rows to get data
For Each drData as DataRow in dtData.Rows
xlsCells(drSheet("StartRow") + dtData.Rows.IndexOf(drData), drDataCols("DataColumn")) = drData("Col" + drDataCols("DataColumn").toString).toString
Next
Next
Next
xlsSheet.SaveAs(newFile)
xlsBook.Close
xls.Quit()
Every time you write to a cell Excel recalculates the open workbooks and refreshes the screen. Both of these things are slow, so you need to set Application.Screenupdating=false and Application.Calculation=xlCalculationManual
Also there is a high overhead associated with each write to a cell, so it is much faster to acuumulate the data in an array and then write the array to the range with a single call to the Excel object model.
With auto mode calculation, recalculation occurs after every data input/changed. I had the same problem, was solved by setting Manual calculation mode. (Reference MSDN link.)
xls.Calculation = Excel.XlCalculation.xlCalculationManual
Also, this property can only be set after a Workbook has been opened or it will throw a run-time error.
One way that has saved me over the years is to add
Application.ScreenUpdating = False
directly before I execute a potentially lengthy method, and then
Application.ScreenUpdating = True
directly after, or at least at some later point in the code. This forces Excel to not redraw anything on the visible screen until it is complete That issue is where I've found lengthy running operations to stem from quite often.