2

My application typically recieves a string in the following format:
" Item $5.69 "

Some contants I always expect:
- the LENGHT always 20 characters
- the start index of the text always [5]
- and most importantly the index of the DECIMAL for the price always [14]
In order to identify this string correctly I validate all the expected contants listed above ....

Some of my clients have now started sending the string with Doube-High / Double-Wide values (pair of characters which represent a single readable character) similar to the following: " Item $x80x90.x81x91x82x92 "

For testing I simply scan the string character-by-character, compare char[i] and char[i+1] and replace these pairs with their corresponding single character when a match is found (works fine) as follows:

[Code]

for (int i=0; i < sData.length(); i++) { char ch = sData[i] & 0xFF; char ch2 = sData[i+1] & 0xFF; if (ch == '\x80' && ch2 == '\x90') zData.replace("\x80\x90", "0"); else if (ch == '\x81' && ch2 == '\x91') zData.replace("\x81\x91", "1"); else if (ch == '\x82' && ch2 == '\x92') zData.replace("\x82\x92", "2"); ... ... ... } 

[/Code]

But the result is something like this:
" Item $5.69 "

Notice how this no longer matches my expectation: the lenght is now 17 (instead of 20) due to the 3 conversions and the decimal is now at index 13 (instead of 14) due to the conversion of the "5" before the decimal point.

Ideally I would like to convert the string to a normal readable format keeping the constants (length, index of text, index of decimal) at the same place (so the rest of my application is re-usable) ... or any other suggestion (I'm pretty much stuck with this)... Is there a STANDARD way of dealing with these type of characters?

Any help would be greatly appreciated, I've been stuck on this for a while now ...

Thanks,

6
  • search for "convert wide char to char". if you do find a solution please post it. if no one finds a solution for a few days, I will try to write up something. Commented May 8, 2010 at 20:30
  • stackoverflow.com/questions/258050/… Commented May 8, 2010 at 20:32
  • Won't using WideCharToMultiByte still change the constants (like the overall string size, location of the decimal, etc...)? Commented May 8, 2010 at 20:52
  • What the heck kinda code is that? Are they treating you like a printer or something? It is not Unicode. Commented May 8, 2010 at 21:07
  • Maybe, my assumption is that this is actually some kind of receipt data ... But if it is not unicode ... then what is it? Commented May 8, 2010 at 21:14

1 Answer 1

1

You need Unicode Normal Form. This Page will help you, in spite of being about VS8. NormalizeString API is independent of the version of Visual Studio in use.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.