This question already has answers here:
Escape double quotes in a string
(9 answers)
How can I add double quotes to a string that is inside a variable?
(20 answers)
Closed 7 years ago.
I have been looking at this for a while trying everything I can find on SO. There are many posts but I must be missing something.
I am building a string and need to get a double quote in it between two variables.
I want the string to be
convert -density 150 "L:\03 Supervisors\
The code is
tw.WriteLine(strPrefix + " " + strLastPath);
where
strPrefix = convert -density 150
and
strLastPath = L:\\03 Supervisors\
I have tried many combinations of "" """ """" \" "\ in the middle where the space is being inserted.
Please show me what I am missing.
You have two options:
var output1 = strPrefix + "\"" + strLastPath;
Or using a verbatim string:
var output2 = strPrefix + #"""" + strLastPath;
Here's a sample console application that achieves what you're after:
namespace DoubleQuote
{
class Program
{
static void Main(string[] args)
{
var strPrefix = "convert - density 150";
var strLastPath = #"L:\\03 Supervisors\";
Console.WriteLine(strPrefix + " \"" + strLastPath);
Console.ReadKey();
}
}
}
If written as a format string it would look like this:
var textToOutput = string.Format("{0} \"{1}", strPrefix, strLastPath);
Console.WriteLine(textToOutput);
Please try this
var strPrefix = "convert -density 150";
var strLastPath = #"L:\03 Supervisors\";
Console.WriteLine(strPrefix + " " + '"'+strLastPath);
Related
I am working on C# POS. I am using raw printing helper and I am trying to print an image using ESC/POS commands with the command: ESC *.
So far I am able to:
string carriageReturn = Convert.ToString((char)13);
string lineFeed = carriageReturn + Convert.ToString((char)10);
string cutPaper = Convert.ToString((char)27) + Convert.ToString((char)105);
string horizontalTab = Convert.ToString((char)9);
string fontSize4 = Convert.ToString((char)29) + Convert.ToString((char)33) + Convert.ToString((char)51);
And I send the data to print with this:
printWithStringAndPrinter(fontSize4 + "this" + lineFeed + "is" + lineFeed + fontSize2 + "test" + lineFeed + cutPaper, p.name);
The only problem is with the image, I can not get it to print. I have tried this:
Bitmap bmp = new Bitmap("C:\\test.bmp");
string image = Convert.ToString((char)27) + Convert.ToString((char)42) + Convert.ToString((char)33) + Convert.ToString((char)0) + Convert.ToString((char)86) + bmp.ToString();
But nothing works. Can someone give an advice or an example of how to print an image?
Even though there are a lot of questions about the same topic, any of them has helped me.
Its a c# code written in a SSIS script task component.
PS_script + #"""$compname = " "\" + Row.computername"\" +
"$appname =" + Row.applicationname + " $appvalue = " + Row.appvalue +
"";
I am tying the MS deploy and setting params coming from table driven. The above statement throws error as I am not able to pass double quotes in computername param.
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/verbatim
In C#, a literal string with the prefix #, "" will be replaced by ".
Example :
var str = #"$compname = """ + Row.computername + #"""";
If the variable Row.computername has the value SERV01, then the result will be :
$compname = "SERV01"
You can also escape a character with \. Then \" will be replaced by ".
Example :
var str = "$compname = \"" + Row.computername + "\"";
If the variable Row.computername has the value SERV01, then the result will be :
$compname = "SERV01"
In you case, you can also use string.Format to more lisibility :
string.Format(
#" $compname = ""{0}"" $appname = ""{1}"" $appvalue = ""{2}""",
Row.computername, Row.applicationname, Row.appvalue
);
Warning, with SSIS script task, you can't use string interpolation (the literal string prefix $).
I am trying to export the drawing to save another drawing using "CopyBase" and "PasteClip" command. But it is does not work an error occurred. Can anyone tell how to i solve this..
i am using Copy and Paste command like this..
AcadApplication acadApp;
AcadDocument thisdrawing;
acadApp = Marshal.GetActiveObject("AutoCAD.Application.20") as AcadApplication;
acadApp.Visible = true;
thisdrawing= acadApp.ActiveDocument;
thisdrawing.Activate();
string str = "_CopyBase" + char.ConvertFromUtf32(13) + "0,0,0" + char.ConvertFromUtf32(13) + "M" + char.ConvertFromUtf32(13) + "G" + char.ConvertFromUtf32(13) + "QWERT" + "\n" + char.ConvertFromUtf32(13);
thisdrawing.SendCommand(str);
string dwgTempPath = "acad.dwt";
newThisdrawing = acapp.Documents.Add(dwgTempPath ) ;
newThisdrawing.SaveAs(expDwgName , thisdrawing.Application.Preferences.OpenSave.SaveAsType,null);
newDwgCreatBool = true;
newThisdrawing.Regen(AcRegenType.acActiveViewport);
newthisdrawing.Activate();
comStr = "pasteclip" + "\n" + "0,0" + "\n";
newThisdrawing.SendCommand(comStr);
Thanks in Advance..
With your edit, I'm assuming this is an external exe. With that in mind and some minor modifications to your code, I got this to work with no problems in a Console exe. Before the code a couple things about it:
I compiled using the 4.5 Framework. The COM references for .NET may have been updated with their .NET API counterparts, so make sure this is the case for you too.
Add a COM reference to "AutoCAD 2015 Type Library" there's one for each language package (choose axdb20enu.tlb, but I think in the end VS may select them all after it's added).
Add a COM reference to "AcObjClassImp 1.0 Type Library", choose the one for release 20 (AcObjClassImp20.tlb)
Add the using statement "using AutoCAD;" at the top with the rest.
Here's the code I used:
static void Main(string[] args)
{
IAcadApplication acadApp;
IAcadDocument thisdrawing;
acadApp = Marshal.GetActiveObject("AutoCAD.Application.20") as AcadApplication;
acadApp.Visible = true;
thisdrawing = acadApp.ActiveDocument;
thisdrawing.Activate();
string str = "_CopyBase" + char.ConvertFromUtf32(13) + "0,0,0" + char.ConvertFromUtf32(13) + "M" + char.ConvertFromUtf32(13) + "G" + char.ConvertFromUtf32(13) + "QWERT" + "\n" + char.ConvertFromUtf32(13);
thisdrawing.SendCommand(str);
string dwgTempPath = "acad.dwt";
IAcadDocument newThisdrawing = acadApp.Documents.Add(dwgTempPath);
//Instead of the path below, use your full path, formatted correctly
newThisdrawing.SaveAs(#"C:\Acad\Test.dwg", thisdrawing.Application.Preferences.OpenSave.SaveAsType, null);
newThisdrawing.Regen(AcRegenType.acActiveViewport);
newThisdrawing.Activate();
string comStr = "pasteclip" + "\n" + "0,0" + "\n";
newThisdrawing.SendCommand(comStr);
}
This question already has answers here:
String format currency
(8 answers)
Closed 8 years ago.
I need to format my display tostring results to a currency in C#
display = "Service Amount: " + service + "<br>" +
"Discount Amount: " + discountAmount + "<br>" +
"Total: " + total + "<br>";
lblDisplay.Text = display;
I did try the following:
display = "Service Amount: " + Console.Write(int.ToString("c",service)) + "
but I couldn't figure out what variables to put in. I just need it to display as $35.00 after the it returns the string.
Try:
display = string.Format("Service Amount: {0}",service.ToString("C"));
Console.WriteLine(display);
You can also look at StringBuilder for building strings or String.Format
String.Format("Service Amount: {0:C}<br>", service)
As far as i understood, a string with an # in required a set of double quotes to insert the quote in to the string?
I have tried that principle and to no avail. The following line works, but if i were to replace those strings with parameter values then i cant seem to get the correct compilation value
var node = doc.SelectSingleNode(#"//node[#label = ""Chemist Name""]/node[#label = ""John,Smith""]");
my attempt (of which i have tried several versions and ended up here, where i have now givn up !)
var node = doc.SelectSingleNode(#"//node[#label = " + ""+parentID+"" + "]/node[#label = " + ""+ name +"" + "]");
can anyone help me please?
Use single quotes:
var node = doc.SelectSingleNode
(#"//node[#label = 'Chemist Name']/node[#label = 'John,Smith']");
var node = doc.SelectSingleNode(
string.format(#"//node[#label = '{0}']/node[#label = '{1}']"
, parentID, name));
You are missing another double quote to close the string being appended and also # before each string containing "".
Try this:
var node =
doc.SelectSingleNode(#"//node[#label = """ + parentID + #"""]/node[#label = """ + name + #"""]");
var node = doc.SelectSingleNode(string.format(#"//node[#label = ""{0}""]/node[#label = ""{1}""]", parentId, name));
Write an extension method to extend string:
public static string Quote(this string input)
{
return string.Format(#"""{0}""", input);
}
And then use it as follows:
var node = doc.SelectSingleNode(#"//node[#label = " + parentID.Quote() + "]/node[#label = " + name.Quote() + "]");
Or simply:
var node = doc.SelectSingleNode(string.Format(#"//node[#label = {0}"]/node[#label = {1}"]",parentID.Quote(), name.Quote());