How to use double quotations in a URL in VB.net? - vb.net

I want to use double quotations in the URL of my VB software, tried nearly everything but nothing works. Any suggestions?
For example, I want my program to search on for "Powered by BlogEngine.NET" but instead it searches without quotations like Powered by BlogEngine.NET
Dork = " ""Powered by BlogEngine.NET"""
Searchterm = FlatTextBox1.Text
Input = FlatTextBox1.Text
System.Diagnostics.Process.Start("http://www.google.com/search?q=" + Dork + " " + Searchterm + " " + TLD + "&tbs=qdr:" + UDate + "&num=" + Numbers)

I see you have this working now but a better approach (also mentioned by #halfer) would be to build the url string then use HttpUtility.URLEncode to properly convert the quotes and any other characters.

Related

.Net Core Data Annotation clarification

Can someone please guide which one of the below is the correct Data Annotation, if I want to allow just alphabets:
[RegularExpression(#"[a-zA-Z]*", ErrorMessage = "Invalid {0}")]
OR
[RegularExpression(#"^[a-zA-Z]*", ErrorMessage = "Invalid {0}")]
Both seems to be working. The difference is ^ symbol.
^ Caret is a Position Anchor.
Position Anchors does not match character, but position such as start-of-line, end-of-line, start-of-word and end-of-word.
In this case you need both ^ and $: start-of-line and end-of-line respectively. E.g., ^[0-9]$ matches a numeric string.
So you should go with,
[RegularExpression(#"^[a-zA-Z]*$", ErrorMessage = "Invalid {0}")]
Becase you need strings starts and ends with alphabetical characters only, not having any other characters such as symbols or numerals. Here are some examples that you can play with.
let str1 = 'abcDef';
let str2 = '123abcDef';
let str3 = 'abcDef123';
let str4 = 'abc123Def';
let my_regex = /^[a-zA-Z]*$/;
let your_regex = /[a-zA-Z]*/;
alert(str1 + " : " + my_regex.test(str1) + " with my regex");
alert(str2 + " : " + my_regex.test(str2) + " with my regex");
alert(str3 + " : " + my_regex.test(str3) + " with my regex");
alert(str4 + " : " + my_regex.test(str4) + " with my regex");
alert(str1 + " : " + your_regex.test(str1) + " with your regex");
alert(str2 + " : " + your_regex.test(str2) + " with your regex");
alert(str3 + " : " + your_regex.test(str3) + " with your regex");
alert(str4 + " : " + your_regex.test(str4) + " with your regex");
The Caret (^) character is also referred to by the following terms:
Terminology
hat, control, uparrow, chevron, circumflex accent
Usage
It has two uses in regular expressions:
To denote the start of the line
If used immediately after a square bracket ([^) it acts to negate the set of allowed characters (i.e. [123] means the character 1, 2, or 3 is allowed, whilst the statement [^123] means any character other than 1, 2, or 3 is allowed.
Character Escaping
To express a caret without special meaning, it should be escaped by preceding it with a backslash; i.e. ^.
You can find it here...
I think you want something more like this:
[RegularExpression(#"^[a-zA-Z]+$", ErrorMessage = "Invalid {0}")]
which says to match
the beginning of the string ^
followed by 1 or more alphabetic characters [a-zA-Z]+ (you do need more than zero right)?
followed by the end of the string $
This doesn't allow other strings to match such as 123abc or abc123 because the anchors of ^ and $ prevent that.
In your first example, the match would allow an empty string, and would allow for the cases I mentioned in the paragraph above. Your second example would allow empty string, but would at least filter out 123abc but would still allow abc123 because you don't have the $ marker.
If you want to take my solution and extend it beyond ASCII alphabetic characters, you can change [a-ZA-Z]+ to \p{L}+, which should work universally in Unicode (but that seems like it might be more than you're looking for; just including for completeness).
Finally, [RegularExpression] uses the standard regex capability that has been part of .NET for quite some time, expressed in the Regular Expression Language - Quick Reference.

SqlFieldsQuery with 'like' for IGNITE

Stuck with a problem, I've got simple query:
private final static String QUERY_2_GET_ID = "select reg." + Cache.EVENT_DT +
" from " + CACHE_TABLE_NAME + " as reg" +
" where " + Cache.ID + " like '?%'");
I crucially need part with '?%' but it returns no result when I execute it with java code
FieldsQueryCursor<List<?>> queryResult = cache.query(QUERY_2_GET_ID.setArgs(id));
List<List<?>> queryAll = queryResult.getAll();
It executes perfectly through SQL console though. Can anybody suggest why is it happening and maybe some solution? Thanks in advance!
Adding to the comment, why can't you just do " like ?").setArgs(id + "%")? :)

Does Xpath to find web element in Selenium use single quote or double quote to wrap the value?

I m wondering, does Xpath use ' or " for the value ?
I have this web element that I want to grab
<div class="has-error ng-scope ng-hide" ng-show="element['ServerValidationFailed']">Sorry, that isn't a valid number.</div>
Normally Xpath should have this pattern Xpath=//tagname[#attribute='value']
But when I tried using ' to surround the value like these
//div[#ng-show='element['ServerValidationFailed']'] and
//div[text()='Sorry, that isn't a valid number.'] ,
these don't work (Google Chrome Developer Tool won't find the web element).
When I tried " for the value like these
//div[#ng-show="element['ServerValidationFailed']"] and
//div[text()="Sorry, that isn't a valid number."]
It works fine (Chrome Developer tool will find a match).
I am a bit confused now, should it be single quote ' or double quote " ?
Either one works fine. It comes down to the content you want to match against.
Examples shown in w3.org xpath abbreviated syntax suggests double quotes (").
The reason is because you can escape " with \" but you cannot escape ' with \'.
If the value you want to match contains ' character, you should use " to wrap the value.
//div[#ng-show="element['ServerValidationFailed']"]
If the value you want to match contains " but not ', you can use ' to wrap the value.
//div[#ng-show='element["ServerValidationFailed"]']
If the value you want to match contains both " & ', you have to use " to wrap the value and escape your " in your value with \".
//div[#ng-show="element['ServerValidationFailed']==\"0\""]
This will match something like
<div ng-show="element['ServerValidationFailed']=="0""></div>
Not saying you should do this but just in case if you need it.
The xpath supports both single and double quotes for defining the attributes, but in case of single quote escaping it doesn't follow the general programming concept. So in case of single quote escaping always put attribute value in double quotes .
Please have a look:: https://github.com/xmlunit/xmlunit/issues/110
This is what i use for this specific condition of single and/or double quotes.
Try this and check with the text you need to verify.
if (!TextString.contains("'")) {
XPath = "//*[contains(text(), \"" + TextString + "\")]" + " | " + "//*[contains(normalize-space(), \"" + TextString + "\")]";
} else if (!Label.contains("\"")) {
XPath = "//*[contains(text(), '" + TextString + "')]" + " | " + "//*[contains(normalize-space(), '" + TextString + "')]";
} else {
XPath = "//*[contains(text()," + "concat('" + TextString.replace("'", "',\"'\",'") + "'))]" + " | " + "//*[contains(normalize-space()," + "concat('" + TextString.replace("'", "',\"'\",'") + "'))]";
}

Run time error in spreadsheet

thank you for your time. I've put stars on the error line if this helps.
I'm lost with an error and I can't find the reason. Can I get some help, please? The macros is not running for only one period and I didn't find any different data in the database compare to the previous period
That's the debug menu:
Get values and convert to string for text box:
a = Format(.Cells(rowNum, dateCol), "dd mmm")
a = a + ", " + Str(.Cells(rowNum, actualAssetCol))
Get values and convert to string for text box:
a = Format(.Cells(rowNum, dateCol), "dd mmm")
a = a + ", " + Str(.Cells(rowNum, actualAssetCol))`
The string concatenation operator in vba is & and not +. Thus, use it like this:
a = a & ", " & Str(.Cells(rowNum, actualAssetCol))`

SSRS - Line break in Matrix cell

In a SSRS Matrix cell I want to be able to have a line break between each output given.
I have the following code in my MS SQL Server Stored Procedure which I then point my SSRS report to
SELECT Customer, Hostname, (QName + QHostname + Qtag + QSerial + QCategory + QType + QItem + QManu + QModel + QVersion) AS AdditionalInfo1
FROM TableQ
At the moment in the AdditionalInfo1 cell when one of the options is returned they are separated by a comma
e.g.
QName, QHostname, Qtag.
Instead I would like them to be separated by a line break all within the same cell
e.g.
QName
QHostname
Qtag
I have tried putting + char(13) + between each Q... in AdditionalInfo1 but this didn't work.
For SSRS, you want to use Chr(10), not Chr(13). I've used this in expressions and as a Join delimiter argument and it produced the desired effect: line breaks within the textbox.
Edit:
Below is an expression that will include the fields with line breaks if a value is present, or omit both if the field is null.
=Fields!QName.Value
+ IIF(ISNOTHING(Fields!QHostname.Value),"", vbCrLf + Fields!QHostname.Value)
+ IIF(ISNOTHING(Fields!Qtag.Value),"", vbCrLf + Fields!Qtag.Value)
+ IIF(ISNOTHING(Fields!QSerial.Value),"", vbCrLf + Fields!QSerial.Value)
+ IIF(ISNOTHING(Fields!QCategory.Value),"", vbCrLf + Fields!QCategory.Value)
+ IIF(ISNOTHING(Fields!QType.Value),"", vbCrLf + Fields!QType.Value)
+ IIF(ISNOTHING(Fields!QItem.Value),"", vbCrLf + Fields!QItem.Value)
+ IIF(ISNOTHING(Fields!QManu.Value),"", vbCrLf + Fields!QManu.Value)
+ IIF(ISNOTHING(Fields!QModel.Value),"", vbCrLf + Fields!QModel.Value)
+ IIF(ISNOTHING(Fields!QVersion.Value),"", vbCrLf + Fields!QVersion.Value)
Instead of concatenating all the 'Q' columns into a single string keep them as separate fields. Then create individual placeholders in a single cell, one for each field. You can do this quite quickly by clicking into the cell (which is rich TextBox) and typing the field name (as it appears in the DataSet) enclosed by square brackets
eg:
[QName]
[QHostname]
[Qtag]