I want to make a link from what the user filepath that is given from an openfiledialog. But I can't get all the quotes in the right places
DOCTextBox.Text = "" & TitleTextBox.Text & ""
In order to put a " in a VB.Net string literal, you need to write "".
For example:
"<a href=""" & HttpUtility.HtmlAttributeEncode(OpenFileDialog1.FileName) _
& """target=_""blank"">" & HttpUtility.HtmlEncode(TitleTextBox.Text) & "</a>"
DOCTextBox.Text = "" & TitleTextBox.Text & ""
It sounds like you're trying to add quotes into the final string produced from the expression. In order to do that use a pair of double quotes "". For example
""
You can use triple quotes such as """
Related
I'm trying to add quotations to a piece of string that is broken in 2 pieces with a variable in the middle.
I have tried many, many ways...many ways and failed.
Example:
Dim path as String = "C:\Users\" & CurrentUser & "\folder\path to something\"
I need the whole result to be in quotations to pass it to a command that requires the path with spaces in quotations.
"C:\Users\Nemo\Folder\Path to something\"
Any help is appreciated.
You should just be able to use "" inside the string assignment that you have. So with your example it would look like this:
Dim path As String = """C:\Users\" & CurrentUser & "\folder\path to something\"""
IMHO it is a good idea to use CHR(34) instead of actual quotes when concatenating strings. Your code should look like this:
Dim current user as string="Nemo"
Dim path as String = CHR(34) & "C:\Users\" & CurrentUser & "\folder\path to something\" & CHR(34)
The result will be:
"C:\Users\Nemo\folder\path to something\"
In a string I have something like "First & vbCrLf & Name" - however, I want to take out the & vbCrLf & so it doesnt cause a line break.
I have done something like
If theString.Contains("& vbCrLf &") Then
' and replace, could do this above of course, but I just want it to go into the IF
End If
and
If theString.Contains("\n") Then
' and replace, could do this above of course, but I just want it to go into the IF
End If
and even "\r\n" but to no avail.
What am I missing?
If theString.Contains(vbCrLf) Then
'Do something
End If
Alternatively...
theString = theString.Replace(vbCrLf, "")
Try:
If theString.Contains(Environment.NewLine) Then
' Code goes here
End If
Remove the vbCrLf from the string literal in Contains.
testVal = testVal.Replace(vbCrLf, String.Empty).Replace("&", String.Empty)
Metacharacters not supported by VB.Net for Strings - can be used with RegEx and probably a few other .Net functions.
In your OP I think you intended:
If theString.Contains("& vbCrLf &") Then
to be
If theString.Contains(vbCrLf) Then
You can test for and replace in one command:
Dim s As String = vbCrLf
MsgBox(s.Length)
s = s.Replace(vbCrLf, "")
MsgBox(s.Length)
I am using START-PROCESS to call MSTEST with multiple arguments that define the container and test settings, however I think it's choking on the way I'm concatenating this. Should I use some other method of constructing this string before putting it into START-PROCESS?
Dim rwSettings As String = "\\PerfvsCtlr2\LoadtestSettings\PerfVSCtlr2forRemote.testsettings"
Dim rwContainer As String = "\\PerfvsCtlr2\LoadTest\LoadTestDefs\Heifer_Interactive_Peak_Workload.loadtest"
Dim rwResults As String = Workload.txtRwResults.Text
System.Diagnostics.Process.Start(Environment.GetEnvironmentVariable("VS110COMNTOOLS") & "..\Ide\MSTEST.EXE", "/Testsettings:""" & rwSettings & "" & " /Testcontainer:""" & rwContainer & "" & " /Resultsfile:""" & rwResults & "")
The problem is unknown currently, because process.start opens and closes the window far too quickly for me to catch any sort of error message. So my question is two-fold:
Does the above concatenation look correct? Is there a way I can get more information on either the final execution string Process.Start is putting together or the error message it's returning?
You can use Path.Combine to build paths and String.Format to build the arguments for Process.Start:
Dim rwSettings As String = "\\PerfvsCtlr2\LoadtestSettings\PerfVSCtlr2forRemote.testsettings"
Dim rwContainer As String = "\\PerfvsCtlr2\LoadTest\LoadTestDefs\Heifer_Interactive_Peak_Workload.loadtest"
Dim rwResults As String = "Workload.txtRwResults.Text"
Dim fileName = System.IO.Path.Combine(Environment.GetEnvironmentVariable("VS110COMNTOOLS"), "Ide\MSTEST.EXE")
Dim args = String.Format("/Testsettings:{0} /Testcontainer:{1} /Resultsfile:{2}", rwSettings, rwContainer, rwResults)
System.Diagnostics.Process.Start(fileName, args)
However, i must admit thar i'm not sure if this yields the desired result. It might give you an idea anyway.
I suspect that your problem is that you are not closing your quotation marks, for instance:
" /Testcontainer:""" & rwContainer & ""
Should be:
" /Testcontainer:""" & rwContainer & """"
Notice that the double-quotation mark at the end needs to be a quadruple quotation mark. Simply saying "" means an empty string.
Should you use something else? Probably. It would be more readable and efficient if you used StringBuilder or String.Format, but even so, you'll still have to fix the closing quotes issue.
I feel dumb for not being able to figure this out, but I can't seem to find a post or google search that seems to get this to make sense to me. I have the following code:
Select Case frmRMAT.TblRMATrackDataGridView.Item("courier", 1).Value.ToString
Case "FedEx"
sTrackNum = "<a href=""https://www.fedex.com/fedextrack/?tracknumbers=""" & frmRMAT.TblRMATrackDataGridView.Item("tracking_num", 1).Value
End Select
as you can see I have escaped the first part, but I need the actual value to be included. It is currently giving me this value:
sTrackNum = "<a href="https://www.fedex.com/fedextrack/?tracknumbers="689691090971 "
So I do not need the " before the actual tracking number. How do I manipulate the quotes so that I obtain a proper html string? Thanks
Just omit the quotes you don't want to have.
Use
sTrackNum = "<a href=""https://www.fedex.com/fedextrack/?tracknumbers=" & frmRMAT.TblRMATrackDataGridView.Item("tracking_num", 1).Value
instead of
sTrackNum = "<a href=""https://www.fedex.com/fedextrack/?tracknumbers=""" & frmRMAT.TblRMATrackDataGridView.Item("tracking_num", 1).Value
You could also use XML literals:
sTrackNum = <a href=<%= "https://www.fedex.com/fedextrack/?tracknumbers=" & frmRMAT.TblRMATrackDataGridView.Item("tracking_num", 1).Value %>></a>
Why, when I do im my code:
"Land Location \\r\\n Roundoff (C)"
I see the \\r\\n and not a new line feeder at the output?
Any idea how to do that?
As I said I must have only one string there, without using a "&". Can I put that vbCrLf inside of my string somehow?
There is no \ escape codes in VB so you can't put a line break in a string literal. The only escape character in VB strings is the double quotation marks used to insert a quotation mark in a string.
You can use the VB constant for a Windows type line break:
"Land Location " & vbCrLf & " Roundoff (C)"
For the code to be platform independent, you should use the NewLine property instead:
"Land Location " & Environment.NewLine & " Roundoff (C)"
Whether you should use the platform independent code or not depends on the situation.
If you need it as a single string for some reason, you would have to use a marker for the line break, that you replace when you use the string:
Dim s As String = "Land Location \n Roundoff (C)"
s = Replace(s, "\n", Environment.NewLine)
May be "Land Location " & vbCR & vbLF .....
--
Edit: per #JeffSahol's comments, you can use string interpolation since VB 14, so it can be like
$"...{vbCrLf}..."
Instead of including the newline manually in the String use System.Environment.NewLine.
vbCrLf
vbCr
vbLf