文本框输入产品编号解码 [英] textbox input product number decode

查看:99
本文介绍了文本框输入产品编号解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的项目,我需要输入产品代码并点击解码,让它在文本框中显示解码值。



示例输入:001122A1BS0902323 < br $>


0011 - 生产国

22A - 工厂位置

1BS - 电气

090 - 灯

2323 - 生产线编号



i有5个可能的匹配列表,我需要匹配每个分开的数字组反对的输入文本。任何帮助,以确定最好的方式去做这件事将不胜感激。所以,如果我输入001122A1BS0902323并点击解码,我将有5个文本框,显示解码输入字符串的每个结果。









- 编辑 -

操作系统:Windows



或多或少我想要反馈不同的方法,以避免编写太多代码来完成简单的事情。我想要构建一个char数组,每个字符将被分别划分,并且必须组装成我需要的长度然后搜索。我看到substring处理它更好..不知道为什么我没想到这一点开始。所有输入(如果有的话)。

I have a simple project where i need to enter a product code and hit decode to have it display the decoded values in textboxes.

example input: 001122A1BS0902323

0011 - country of manufacture
22A - plant location
1BS - electrical
090 - lamp
2323 - line production number

i have 5 lists of possible matches for each separated set of numbers that i need to match the inputed text against. any help in figuring the best way to go about this would be appreciated. so if i input 001122A1BS0902323 and hit decode i will have 5 textboxes that show me each result from decoded input string.




-- edited --
OS: Windows

More or less I wanted feedback on different methods to avoid writing too much code to accomplish something simple. I thought about building one char array to which each character would be divided separately and have to be assembled into the length i needed then searched. I see substring handles it better.. not sure why i wasn't thinking of that to begin with. All input if any appreciated.

推荐答案

假设(根据您的描述)字段是固定长度的,将每个项目复制到新的字符数组是一件简单的事情,使用C ++的许多字符串处理方法之一。然后,您可以使用该字符串在各种列表中搜索您在文本框中显示的相应名称。
Assuming (from your description) that the fields are fixed length, it is a simple matter to copy each item to a new character array, using one of the many string handling methods of C++. You can then use the string to search in your various lists for the corresponding name which you display in the textbox.


正如 Richard 所建议的,如果产品代码有固定的格式,那么这很简单。

例如,您可以使用 string :: substr [ ^ ]提取字段值然后尝试匹配它知道字段值,使用例如(可能是无序的)地图(例如,参见 map :: find [ ^ ])。
As already suggested by Richard, if the product code has a fixed format, then it is a simple matter.
For instance you may use string::substr[^] to extract a field value and then try to match it with know field values, using, for instance a (possibly unordered) map (see, for instance map::find[^]).


这是非常好的。

你应该使用String.Substring方法(Int32,Int32)方法。



您可以这样使用



This is very to do that.
You should use String.Substring Method (Int32, Int32) method.

You can use it like this

string Encoded = "001122A1BS0902323";

string COM=Encoded.Substring(0,4);
string PL=Encoded.Substring(4,3);
string Ele=Encoded.Substring(7,3);
string Lamp=Encoded.Substring(10,3);

string LPN=Encoded.Substring(13,4);


这篇关于文本框输入产品编号解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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