WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Strings

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Convert Special Characters

 Keywords: convert special characters accents 

Question:

Is there a function convert special characters to normal ones? I've got a large XML file containing names with special characters, like Frédéric, Dvorák, etc, and want to replace characters that have an accent with the equivalent without an accent.I'm hoping someone has already done this, so I don't have to create the function from scratch.

Answer:

I had the same problem and used binary tables to convert. Like
InputFile = 'c:\input.txt'
OutputFile = 'c:\output.txt'
FSize = FileSize(InputFile)

; $-0 $-1 $-2 $-3 $-4 $-5 $-6 $-7 $-8 $-9 $-A $-B $-C $-D $-E $-F
Row0 ="000 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015" ;| $0- |
; NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI | |
Row1 ="016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031" ;| $1- |
; DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US | |
Row2 ="032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047" ;| $2- |
; SP ! " # $ % & ' ( ) * + , - . / | |
Row3 ="048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063" ;| $3- |
; 0 1 2 3 4 5 6 7 8 9 : ; < = > ? | |
Row4 ="064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079" ;| $4- |
; @ A B C D E F G H I J K L M N O | |
Row5 ="080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095" ;| $5- |
; P Q R S T U V W X Y Z [ \ ] ^ x | |
Row6 ="096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111" ;| $6- |
; ` a b c d e f g h i j k l m n o | |
Row7 ="112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127" ;| $7- |
; p q r s t u v w x y z { | } ~ DEL | |
Row8 ="032 032 044 051 044 046 043 032 094 032 083 032 032 032 090 032" ;| $8- |
; €=S ?=S ‚=, ƒ=# „=, …=. †=+ ‡=S ˆ=^ ‰=S Š=S ‹=S Œ=S ?=S Ž=Z ?=S | |
Row9 ="032 039 039 039 039 046 045 045 039 032 115 032 032 032 122 089" ;| $9- |
; ?=S ‘=' ’=' “=' ”=' •=. –=- —=- ˜=' ™=S š=s ›=S œ=S ?=S ž=z Ÿ=Y | |
Row10="032 033 051 036 032 089 033 083 039 032 097 032 032 032 032 045" ;| $A- |
; ?=S ¡=! ¢=# £=$ ¤=S ¥=Y ¦=! §=S ¨=' ©=S ª=a «=S ¬=S ?=S ®=S ¯=- | |
Row11="032 043 032 032 039 117 080 046 044 049 111 032 052 050 051 063" ;| $B- |
; °=S ±=+ ²=S ³=S ´=' µ=u ¶=P ·=. ¸=, ¹=1 º=o »=S ¼=4 ½=2 ¾=3 ¿=? | |
Row12="065 065 065 065 065 065 065 067 069 069 069 069 073 073 073 073" ;| $C- |
; À=A Á=A Â=A Ã=A Ä=A Å=A Æ=A Ç=C È=E É=E Ê=E Ë=E Ì=I Í=I Î=I Ï=I | |
Row13="068 078 079 079 079 079 079 120 048 085 085 085 085 089 080 032" ;| $D- |
; Ð=D Ñ=N Ò=O Ó=O Ô=O Õ=O Ö=O ×=x Ø=0 Ù=U Ú=U Û=U Ü=U Ý=Y Þ=P ß=S | |
Row14="097 097 097 097 097 097 097 099 101 101 101 101 105 105 105 105" ;| $E- |
; à=a á=a â=a ã=a ä=a å=a æ=a ç=c è=e é=e ê=e ë=e ì=i í=i î=i ï=i | |
Row15="111 110 111 111 111 111 111 032 111 117 117 117 117 121 112 121" ;| $F- |
; ð=o ñ=n ò=o ó=o ô=o õ=o ö=o ÷=S ø=o ù=u ú=u û=u ü=u ý=y þ=p ÿ=y | |
; $-0 $-1 $-2 $-3 $-4 $-5 $-6 $-7 $-8 $-9 $-A $-B $-C $-D $-E $-F


;Allocte 256 bytes for a 1:1 translation table
BBXlate=BinaryAlloc(256)
;load translation table from ROW variables above.
; Could have loaded it from a file also, but this is faster
For Rowdigit=0 To 15
   For Coldigit= 0 To 15
      BinaryPoke(BBXlate,(Rowdigit*16)+Coldigit,ItemExtract(Coldigit+1,Row%Rowdigit%," "))
   Next
Next


BytesToAdd=1000
BinBuf = BinaryAlloc(FSize + BytesToAdd)
ReplInput = BinaryRead(BinBuf,InputFile)

;Perform the magic Xlate function
BinaryXlate(BinBuf,bbxlate,0)

Ret = BinaryWrite(BinBuf,OutputFile)
BinaryFree(BinBuf)

Article ID:   W18285
Filename:   Convert Special Characters.txt
File Created: 2009:05:26:13:33:42
Last Updated: 2009:05:26:13:33:42