vb.net - how to correct incoming data that contains char not in Ascii to unicode before saving to the database -
i have webservice api in vb.net accepts string. cannot control data coming api. receive chars in between words in format (–, Á, •ï€,ââ€ï€, etc. ) there way me handle these or convert these characters correct symbols before saving database?
i know best solution go after source characters malformed.. i'll make plan b
my code using utf-8 encoding pattern, if client uses api messed , inadvertently sent malformed char thru api. can clean string , convert malformed char correct symbol?
if want accept ascii characters, remove non-ascii characters encoding , decoding string - default ascii encoding uses "?" substitute unrecognized characters, want override that:
' using system.text dim input string = "âh€eÁlâl€o¢wïo€râlâd€ï€" dim ascii encoding = encoding.getencoding( "us-ascii", new encoderreplacementfallback(" "), new decoderreplacementfallback(" ") ) dim bytes() byte = ascii.getbytes(input) dim output string = ascii.getstring(bytes) output:
h e l l o w o r l d the replacement given en/decoderreplacementfallback can empty if want drop non-ascii characters.
you use different encoding ascii if want accept more characters - imagine of characters listed valid in european character sets.
Comments
Post a Comment