Click here to Skip to main content
15,893,790 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 14-Sep-15 14:55pm
v2
Comments
Wendelius 14-Sep-15 0:21am    
Without any delimiters I'd say this is quite risky. What if you have a product 090 and A3090F or products A109 and 030 and you query with A109030. I would consider some other approach.
chandanadhikari 14-Sep-15 3:00am    
Mika Wendelius makes a good point. But i guess OP is going to follow a standard for breaking up the input string text. First four chars form a set, then next 3 and then next3 and so on. hope i understood this correctly .
chandanadhikari 14-Sep-15 5:29am    
excellent solutions are already here.So the logic part is covered pretty well. Can you please tell us which Operating system you are targetting so that experts here can accordingly recommend libraries/frameworks for building the GUI.
phil.o 14-Sep-15 8:20am    
What are you talking about?
chandanadhikari 14-Sep-15 9:36am    
"...02323 and hit decode i will have 5 textboxes that show me each result..." which probably means OP will need to make some UI also. If i am wrong then kindly correct me.

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.
 
Share this answer
 
Comments
CPallini 14-Sep-15 5:10am    
Of course, 5.
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[^]).
 
Share this answer
 
This is very to do that.
You should use String.Substring Method (Int32, Int32) method.

You can use it like this

C#
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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900