如何使用 StreamWriter 在字符串中添加双引号

本文关键字:添加 字符串 何使用 StreamWriter | 更新日期: 2023-09-27 18:25:35

        using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
        { 
            using (TextWriter tw = new StreamWriter(fs))
        {
            tw.WriteLine("<xpml><page quantity='0' pitch='76.2 mm'></xpml>SIZE 76.2 mm, 76.2 mm");
            tw.WriteLine("DIRECTION 0,0");
            tw.WriteLine("REFERENCE 0,0");
            tw.WriteLine("OFFSET 0 mm");
            tw.WriteLine("SET PEEL OFF");
            tw.WriteLine("SET CUTTER OFF");
            tw.WriteLine("<xpml></page></xpml><xpml><page quantity='1' pitch='76.2 mm'></xpml>SET TEAR ON");
            tw.WriteLine("CLS");
            tw.WriteLine("CODEPAGE 1252");
            tw.WriteLine("TEXT 579,370,&quot;ROMAN.TTF&quot;,180,1,12,&quot;Party Name:&quot;");
            tw.WriteLine("BARCODE 527,546,&quot;128M&quot;,102,0,180,3,6,&quot;!104CR!0991234567890123445r&quot;");
            tw.WriteLine("TEXT 451,439,'ROMAN.TTF',180,1,12,'CR1234567890123445'");
            tw.WriteLine("TEXT 579,329,'ROMAN.TTF',180,1,12,'Order no:'");
            tw.WriteLine("TEXT 579,289,'ROMAN.TTF',180,1,12,'Ref No:'");
            tw.WriteLine("TEXT 579,249,'0',180,13,10,'Date:'");
            tw.WriteLine("TEXT 579,209,'ROMAN.TTF',180,1,12,'W X H:'");
            tw.WriteLine("TEXT 579,169,'ROMAN.TTF',180,1,12,'Prd Ty:'");
            tw.WriteLine("TEXT 579,128,'ROMAN.TTF',180,1,12,'Remarks:'");
            tw.WriteLine("TEXT 392,370,'ROMAN.TTF',180,1,12,'AMI Distributors'");
            tw.WriteLine("TEXT 439,329,'ROMAN.TTF',180,1,12,'"+order_no+"'");
            tw.WriteLine("TEXT 460,289,'ROMAN.TTF',180,1,12,'"+o_ref+"'");
            tw.WriteLine("TEXT 497,249,'0',180,13,10,'"+ttime+"'");
            tw.WriteLine("TEXT 477,209,'ROMAN.TTF',180,1,12,'"+w+""+u+" X "+h+""+u+"'");
            tw.WriteLine("TEXT 472,169,'ROMAN.TTF',180,1,12,'"+pro+"'");
            tw.WriteLine("TEXT 436,128,'ROMAN.TTF',180,1,12,'"+oprating+"'");
            tw.WriteLine("PRINT 1,1");
            tw.WriteLine("<xpml></page></xpml><xpml><end/></xpml>");
            }
        }

叽喳��WriteLine("TEXT 460,289,'ROMAN.TTF',180,1,12,'"+o_ref+"'"(;

在文本文件中打印此"罗马。TTF">,并且不会像这样使用双引号">罗马。啧">

如何使用 StreamWriter 在字符串中添加双引号


您可以使用
'"


在您的字符串中(像这样: "text '"quotedtext'" more text" ( 插入双引号。
使用逐字字符串 ( @"your string text" (,您可以简单地使用两个双引号,如下所示""插入双引号。我希望我没有用那么多引号混淆你......