当将msg变量拆分为更多行时,它不会给出行中的值? [英] When split msg variable to more lines it not give me values in lines?

查看:80
本文介绍了当将msg变量拆分为更多行时,它不会给出行中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



当将msg变量拆分为更多行时,它不会在行中给出值?
$调试中的b $ b msg变量给我下面的文字扫描




详细信息



i在Windows窗体中工作c#vs 2015



i使用条形码阅读器阅读qr代码



条形码扫描器作为USB键盘工作并定义为HID驱动程序



如果我用文本框替换msg变量它在读取数据和吐口水中工作



SUCCESS这样



拆分代码下面的问题是什么?



文本扫描:



30阿拉伯制药联盟大会



用户名: khalid ramzy



国家:沙特阿拉斯



会员资格:部分



序列号:1014



我的代码







Problem

When split msg variable to more lines it not give me values in lines ?
msg variable in debug give me text scanning bellow


Details

i work in windows form c# vs 2015

i using bar code reader to read qr code

bar code scanner working as USB keyboard and define as HID Drivers

if i replace msg variable with text box it working in read data and spiting

SUCCESS so that

what is the problem in splitting below code ?

text scanning :

30 General Conference of Arab Pharmaceutical Unions

UserName : khalid ramzy

Country : Saudia

Membership : part

Serial : 1014

my code



public partial class Form1 : Form
    {
        DateTime _lastKeystroke = new DateTime(0);
        List<char> _barcode = new List<char>(10);
        public Form1()
        {
            InitializeComponent();

        }

        private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
            if (elapsed.TotalMilliseconds > 100)
                _barcode.Clear();

            // record keystroke & timestamp
            _barcode.Add(e.KeyChar);
            _lastKeystroke = DateTime.Now;

            // process barcode
            if (e.KeyChar == 13 && _barcode.Count > 0)
            {

                    string msg = new String(_barcode.ToArray());

                string[] lines = msg.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

                if (lines.Length > 5)
                {
                    string msg1 = lines[1].Substring(lines[1].IndexOf(":") + 1);
                    label3.Text = msg1;
                    string msg2 = lines[2].Substring(lines[2].IndexOf(":") + 1);
                    label4.Text = msg2;
                    string msg3 = lines[3].Substring(lines[3].IndexOf(":") + 1);
                    label5.Text = msg3;
                    string msg4 = lines[4].Substring(lines[4].IndexOf(":") + 1);
                    label6.Text = msg4;
                    label2.Text = lines[5].Substring(lines[5].IndexOf(":") + 1);
                }
                    _barcode.Clear();
            }
        }
    }
}





调试中的msg变量值为扫描二维码



但现在问题



如何将它们拆分为上述行?



我的尝试:





msg variable in debug have values of scanning qr code

but problem now

How to split them to lines as above ?

What I have tried:

when split msg variable to more lines it not give me values in lines?

推荐答案

您是否已将数据加载到HexViewer?你应该注意确认中断/分隔符是CR,NL还是CR + NL字符。扫描仪可能与运行代码的设备/ PC不同,因此 Environment.NewLine 可能不匹配。
Have you loaded the data into a HexViewer? You heed to confirm if the break/seperator is a CR, NL, or CR+NL character(s). The scanner may not be using the same as the device/PC running your code, so Environment.NewLine may be a mismatch.


这篇关于当将msg变量拆分为更多行时,它不会给出行中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆