{"id":547,"date":"2012-11-26T08:48:02","date_gmt":"2012-11-26T08:48:02","guid":{"rendered":"http:\/\/www.bardecode.com\/en1\/?p=547"},"modified":"2013-03-01T15:44:08","modified_gmt":"2013-03-01T15:44:08","slug":"handling-unicode-encoded-barcodes-in-vbnet","status":"publish","type":"post","link":"https:\/\/www.bardecode.com\/en1\/handling-unicode-encoded-barcodes-in-vbnet\/","title":{"rendered":"Handling Unicode Encoded Barcodes in VB.Net"},"content":{"rendered":"<p>2-D barcode formats such as PDF-417 can encode a huge character set, which means that the barcode reader toolkit needs to encode characters outside the normal ASCII range. If the Encoding property is set to 2 then the toolkit will use Unicode encoding, whereby characters can be represented by the string &amp;#N; where N is an integer.<\/p>\n<p>For example:<\/p>\n<p>&amp;#209; represents the character \u00d1<\/p>\n<p>To decode this to a unicode\u00a0string in\u00a0VB.Net you need to process the barcode value through a regular expression replacement as follows:<\/p>\n<p>Step 1:<\/p>\n<p>Create a function to convert the integer values (stored\u00a0in a string) to a single character string holding the character represented by the unicode integer value&#8230;<\/p>\n<p>Private Function MatchHandler(ByVal m As System.Text.RegularExpressions.Match) As String<br \/>\nDim i As Int16<br \/>\ni = Int16.Parse(m.Groups(1).Value, Globalization.NumberStyles.Integer)<br \/>\n&#8216; Suppress null characters.<br \/>\nIf i = 0 Then<br \/>\nReturn &#8220;&#8221;<br \/>\nEnd If<br \/>\nReturn Chr(i).ToString()<br \/>\nEnd Function<\/p>\n<p>Step 2:<\/p>\n<p>In the function where you read the barcode values:<\/p>\n<p>&#8216; Get the barcode value<br \/>\nstrBarcode = barcode.GetBarString(1)<br \/>\n&#8216; Create the delegate and the regular expression<br \/>\nDim myDelegate As New System.Text.RegularExpressions.MatchEvaluator(AddressOf MatchHandler)<br \/>\nDim re As New System.Text.RegularExpressions.Regex(&#8220;&amp;#([0-9]+);&#8221;)<br \/>\n&#8216; Convert the Unicode escape sequences to a regular unicode string<br \/>\nstrBarcode = re.Replace(strBarcode, myDelegate)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2-D barcode formats such as PDF-417 can encode a huge character set, which means that the barcode reader toolkit needs to encode characters outside the normal ASCII range. If the Encoding property is set to 2 then the toolkit will use Unicode encoding, whereby characters can be represented by the string &amp;#N; where N is<\/p>\n<p><a href=\"https:\/\/www.bardecode.com\/en1\/handling-unicode-encoded-barcodes-in-vbnet\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":330,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[61,74,86,19,87,85,72,62,83,88,57],"class_list":["post-547","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development-kits","tag-net","tag-2d-barcode","tag-ascii","tag-barcode","tag-barcode-reader-toolkit","tag-character-sets","tag-pdf-417","tag-software","tag-unicode","tag-vb-net","tag-visual-basic"],"_links":{"self":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/547"}],"collection":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/comments?post=547"}],"version-history":[{"count":6,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/547\/revisions"}],"predecessor-version":[{"id":1656,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/posts\/547\/revisions\/1656"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/media\/330"}],"wp:attachment":[{"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/media?parent=547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/categories?post=547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bardecode.com\/en1\/wp-json\/wp\/v2\/tags?post=547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}