皆さんこんにちは。私が理解していない2つの問題について、誰かが私を助けてくれることを願っています。
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// If the com port has been closed, do nothing
if (!comport.IsOpen) return;
// This method will be called when there is data waiting in the port's buffer
// Determain which mode (string or binary) the user is in
// Read all the data waiting in the buffer
string data = comport.ReadExisting();
textBox1.AppendText(data);
textBox1.ScrollToCaret();
//scnbutton.PerformClick();
// Display the text to the user in the terminal
}
バーコードを扱っています。スキャナーがバーコードをスキャンすると、S08A07934068721 が返されます。UPC がテキストボックスに追加したい値である 07934068721 になるたびに、この値を返します。
string data1= data.Substring(4);
textBox1.AppendText(data1);
これは、サブストリングに使用しようとしたものの例です。
文字列データをサブストリング化しようとするたびに、断片化してしまい、それを止める方法がわかりません。これを修正した後、以下のコードで問題が発生します
textBox1.Text = textBox1.Text.PadLeft(13, '0');
これはうまく機能し、常に13桁を埋めます。しかし、UPC などのタイプの先頭に 0 がある場合、12 桁に下がるのはなぜですか?