How can i find a partial match from output_value and match it to value in a dt_datatable then use the partial match found to add row - datatable

How to find a partial match from output_value and match it to value in a dt_datatable then use the partial match found to add row
output_value = "12345600"
dt_datatable = {"123456", "263456"}
Thank you in advance.

Firstly, from your example above you dont have a datatable, it looks more like a list however for this answer I will assume that you have the following string called output_value and a datatable called dt_datatable with a single column called partial.
output_value = "12345600"
dt_datatable
partial
"123456"
"263456"
The below line of code sort of answers the above question, it will identify the first row as this meets the criteria inferred in your question, output_value starts with whats in the row meaning they have a partial match.
dt_datatable.AsEnumerable.Where(Function (r) output_value.StartsWith(r.Item("partial").ToString())).CopyToDataTable()
This could be tweaked to use other string functions depending on your requirements, for example the below checks if output_value contains the string in the row rather than starts with it.
dt_datatable.AsEnumerable.Where(Function (r) output_value.Contains(r.Item("partial").ToString())).CopyToDataTable()
One of the difficult bits of development and it seems to crop up more in RPA is matching, you need to define exactly what you want to match on then create your rules around that. eg for a match it has to start with it not end with it, or it just must contain it etc...

Related

xpath search from importxml function in google sheets

how do I get "Div/yield" value from here? i've tried //td[node()='Div/yield' and //td[text()='Div/yield'.
and //td[#data-snapfield='latest_dividend-dividend_yield']/following-sibling::td
#sideshowbarker is correct in that there's a newline at the end so looking for an element with the exact text would return 0 results. Another way to do this (one is through #sideshowbarker's answer) is to look for an element that contains this text. So the first step is:
//td[contains(text(),'Div/yield')]
But you don't need this. Your last answer is on the right track. You've identified the element that you're after, but I think you're looking for the text. So you need to add text() at the end:
//td[#data-snapfield='latest_dividend-dividend_yield']/following-sibling::td/text()
But if you want to use the field name, so you could use the xpath for the other fields as well, then just combine these:
//td[contains(text(),'Field name')]/following-sibling::td/text()
Now just replace Field name with the field you're after..
e.g. 'Div/yield': //td[contains(text(),'Div/yield')]/following-sibling::td/text()

How do I write a regex for Excel cell range?

I need to validate that something is an Excel cell range in Ruby, i.e: "A4:A6". By looking at it, the requirement I am looking for is:
<Alphabetical, Capitalised><Integer>:<Integer><Alphabetical, Capitalised>
I am not sure how to form a RegExp for this.
I would appreciate a small explanation for a solution, as opposed to purely a solution.
A bonus would be to check that the range is restricted to within a row or column. I think this would be out of scope of Regular Expressions though.
I have tried /[A-Z]+[0-9]+:[A-Z]+[0-9]+/ this works but allows extra characters on the ends.
This does not work because it allows extra's to be added on to the beginning or end:
"HELLOAA3:A7".match(/\A[A-Z]+[0-9]+:[A-Z]+[0-9]+\z/) also returns a match, but is more on the right track.
How would I limit the number range to 10000?
How would I limit the number of characters to 3?
This is my solution:
(?:(?:\'?(?:\[(?<wbook>.+)\])?(?<sheet>.+?)\'?!)?(?<colabs>\$)?(?<col>[a-zA-Z]+)(?<rowabs>\$)?(?<row>\d+)(?::(?<col2abs>\$)?(?<col2>[a-zA-Z]+)(?<row2abs>\$)?(?<row2>\d+))?|(?<name>[A-Za-z]+[A-Za-z\d]*))
It includes named ranges, but the R1C1 notation is not supported.
The pattern is written in perl compatible regex dialect (i.e. can also be used with C#), I'm not familiar with Ruby, so I can't tell the difference, but you may want to look here: What is the difference between Regex syntax in Ruby vs Perl?
This will do both: match Excel range and that they must be same row or column. Stub
^([A-Z]+)(\d+):(\1\d+|[A-Z]+\2)$
A4:A6 // ok
A5:B10 // not ok
B5:Z5 // ok
AZ100:B100hello // not ok
The magic here is the back-reference group:
([A-Z]+)(\d+) -- column is in capture group 1, row in group 2
(\1\d+|[A-Z]+\2) -- the first column followed by any number; or
-- the first row preceded by any character

XPath & Replace Exact Match

can anyone help me with this?
I'm trying to change fields that have a "0" to Nothing.
I have this:
[str_replace("0",",{price[1]/sale[1]})]
but I think this will replace all fields that "contain" a 0 so for example if it had 301 then it would become 31. What I want is to only replace fields that only contain a single 0 to nothing.
How can I do this? (the code needs to be on a single line as it's run on a form field)
A simple way to do this may be as follows (not tested!):
[{string(price[1][number(sale[1]) != 0]/sale[1])}]
This expression includes an additional condition to only find the number if it is not 0 in the first place. If found it returns the number, otherwise it will return an empty string since the function string of an empty node set should yield exactly this.

Find / search the AOT for an exact match

Is it possible to find (search) in Dynamics AX 2009 for an exact match?
For example, when I am searching in the AOT for "AddressRelationship", I don't want to see DirPartyAddressRelationship in the results.
Okay, it took me a while, but I have figured this out, it Is possible.
Adding a breakpoint to the find form shows that it uses a class called SysUtilScanSource to find your string within the AX source code.
In SysUtilScanSource.do() the method match is used to find a match against the specific source code. You can read more about match here;
http://msdn.microsoft.com/en-us/library/aa886279(v=ax.10).aspx
The match method allows you to use expressions.
The expression you require is as follows;
:SPACE
Where SPACE is the character ' '. Sets the match to blanks, tabulations, and control characters such as Enter (new line).
For example:
match("ab: cd","ab cd"); //returns 1
match("ab: cd","ab\ncd"); //returns 1
match("ab: cd","ab\tcd"); //returns 1
match("ab: cd","ab cd"); //returns 0 - only the first space is matched
Therefore, in your example you need enter the following string in the "containing text" field;
: AddressRelationship:
Note that in the above string there are spaces in the following locations;
:SPACEAddressRelationship:SPACE
Try it. I did, it works a treat.
When you do the find, look at "properties" tab at the end of the find form window. This allows you to scale down the search based on properties. I do not believe there is a way to use an exact match but you can narrow your search down using the properties.

How to match text sequences that continue through child nodes (e.g. with sgml-style markup)?

<bits>
<thing>Match this please</thing>
<thing>Don't match this</thing>
<thing>Match <b>this</b> please</thing>
</bits>
An expression like this:
//thing[text()='Match this please']
will locate the first 'thing' but not the third, because the phrase is distributed through a child node.
Is there an expression that would match the first and the third 'thing' in my example?
Try:
//thing[string()='Match this please']
jsfiddle:
http://jsfiddle.net/ZG9n3/2/
Please check the reference to see if this is going to work for you:
http://www.w3.org/TR/xpath/#function-string
Is there an expression that would
match the first and the third 'thing'
in my example?
You mean: Is there an expression that would select the first and the third element named thing, based on their string value.
Use:
/*/thing[. = 'Match this please']
The predicate compares the string value of the context node to the string "Match this please".
By definition the string value of an element is the concatenation (in document order) of all of its text-nodes descendents.
Note: Always try to avoid the // abbreviation because its use may incur big inefficiency. Whenever the structure of an XML document is known, use a chain of specific location steps.

Resources