我正在试着用c#.net写一个程序
要修改具有以下特性的热敏标签打印机.prn文件
<xpml></page></xpml><xpml><page quantity='25' pitch='35.0 mm'></xpml>N
如何在运行时更改数量属性,方法是将c#.net从25改为用户输入,比如50、100或5?所以它将会是
<xpml></page></xpml><xpml><page quantity='50' pitch='35.0 mm'></xpml>N
或
<xpml></page></xpml><xpml><page quantity='100' pitch='35.0 mm'></xpml>Nenter code here
或
<xpml></page></xpml><xpml><page quantity='5' pitch='35.0 mm'></xpml>N
完整的.prn文件
<xpml><page quantity='0' pitch='35.0 mm'></xpml>I8,A
q843
O
JF
ZT
Q280,25
<xpml></page></xpml><xpml><page quantity='2' pitch='35.0 mm'></xpml>N
b569,70,Q,m2,s5,eL,"12345678"
A686,52,2,4,1,1,N,"12345678"
A823,267,2,4,1,1,N,"Hardware Kit (Egypt)"
b149,70,Q,m2,s5,eL,"12345678"
A266,52,2,4,1,1,N,"12345678"
A403,267,2,4,1,1,N,"Hardware Kit (Egypt)"
P2
<xpml></page></xpml><xpml><end/></xpml>
发布于 2018-06-07 03:49:15
尝试以下操作:
string xml = "<root><xpml><page/></xpml><xpml><page quantity='25' pitch='35.0 mm'/></xpml></root>";
XElement element = XElement.Parse(xml);
XElement page = element.Descendants("page").Where(x => x.Attribute("quantity") != null).FirstOrDefault();
page.SetAttributeValue("quantity", 50);
发布于 2018-06-10 01:41:42
在字符串操作之后,/Regex可以解决我的问题,但是现在我发现不需要修改这一行,只有P命令实际控制所需的打印数量
string pattern = @"(quantity=')([0-9]+)";
Regex regex = new Regex(pattern);
string changedvlu = regex.Replace(rowsInTextFile[6], "quantity='" +
dgvrLabels.Cells["labels2print"].Value.ToString());
string cmdlableqty = rowsInTextFile[6].ToString();
int findpicthpos = cmdlableqty.IndexOf("pitch");
if (findpicthpos>0)
{
rowsInTextFile[6] = "<xpml></page></xpml><xpml><page quantity ="
+ "\'" + dgvrLabels.Cells["labels2print"].Value + "\' ";
rowsInTextFile[6] += cmdlableqty.Substring(findpicthpos);
}
else
MessageBox.Show("Problem in setting label qty:call developer");
https://stackoverflow.com/questions/50717148
复制相似问题