Click here to Skip to main content
15,886,699 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
While decoding the barcode the result of the barcode value is saved in a

std::string str_data the result of the barcode value should be like this

str_data=[)>{RS}0603{GS}(51)KD-78F0443GBGAHAX/01032/T6(53)1256(54)15204D1
1E4-00210A002(55)2015/05/15(56)PARTIAL(57)T.(58)2(59)1(5D)02(5F)
1519 1519XP001(5H)JAPAN(5J)JAPAN(5L)JAPAN(5M)6255-3544(67)0(68)U
PD78F0443GB-GAH-AX(69)002G1S5X@(6B)0001102866(6I)LG-151(6K)JP(6L
)JP(6M)JP{RS}{EOT}

but the value of the result is creating an null space in the result value like
[)>000603?(51)KD-78F0443GBGAHAX/01032/T6(53)1256(54)15204D1
1E4-00210A002(55)2015/05/15(56)PARTIAL(57)T.(58)2(59)1(5D)02(5F)
1519 1519XP001(5H)JAPAN(5J)JAPAN(5L)JAPAN(5M)6255-3544(67)0(68)U
PD78F0443GB-GAH-AX(69)002G1S5X@(6B)0001102866(6I)LG-151(6K)JP(6L
)JP(6M)JP

the null values are highlight in the Bold letters.

and another problem is while converting this std::string value into CString means am getting "[)>" this result only because of the getting null value it is omitting the remaining values.

so, i need the proper way to save this result value..

What I have tried:

I tried to erase the null space using the following code
C++
while(1)
     {
      int letter=a_strdata.find('\0');
      if(letter==-1)
      {
       break;
      }
      a_strdata= a_strdata.erase(letter,1);
     }


It removes the null space and gives the full length of the string of the result but i need the result with the null space or proper conversion.
Posted
Updated 17-Jan-17 4:18am
v2
Comments
CPallini 17-Jan-17 3:11am    
How do you 'convert' from std:.string to CString? Are you using a UNICODE build?
Member 12624812 17-Jan-17 3:15am    
No multicode
using this conversion
std::string str_data.c_str();
converting into CString

The first problem seems to be how your example strings are printed out.

There are parts with control code abbreviations enclosed by parentheses (see Control character - Wikipedia[^]). So it might be that these are placeholders created by the print function.

{RS} for example might be a place holder for the control code 0x1E (RS = Record Separator).

So you have to check first if your std::string really contains {RS} or the byte 0x1E. To check this print the hex code for the first letters.

I assume that I'm right because that would explain why the CString is printed in a different way.

The next check would be printing out the hex values from the CString. They might be the same as for the std::string. Then there was only a problem with the output but not with the assignment.

As already mentioned by CPallini in the comments you might also get problems with Unicode builds. To avoid this you should use CStringA instead of CString if the strings contain only ASCII characters (codes less than 0x80):
C++
CStringA str = a_strdata.c_str();


If the CStringA is still not the same as the std::string check if there are NULL bytes in the input string. If so, you can't use CString. Then you have to use a binary buffer.

A simple check:
C++
CStringA str = a_strdata.c_str();
for (int i = 0; i < str.GetLength(); i++)
    printf("%02X %02X\n", a_strdata.at(i), str.GetAt(i));
 
Share this answer
 
A simple solution is to loop through your str_data and add each char to the CString.

C++
CString c_string;

for (int index = 0; index < str_data.length(); index++){
    c_string += str_data[index];
}

But I think the correct solution is, that the std::string are chars and your CString is multi-byte.
So the best solution should be the conversion constructor:
C++
CString s = CString(str_data);//conversion constructor
 
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