vb.net - Replace special characters in text file. Best way to do this? -


i've got text file lines , special characters. want replace those. best way this? i've got feeling not quickest way.

dim lopenfile long dim sfiletext string dim sfilename string  sfilename = "c:\test.txt"   lopenfile = freefile open sfilename input lopenfile sfiletext = input(lof(lopenfile), lopenfile) close lopenfile  sfiletext = replace(sfiletext, " Ç ", " c ") sfiletext = replace(sfiletext, " ü ", " u ") sfiletext = replace(sfiletext, " é ", " e ")   lopenfile = freefile open sfilename output lopenfile print #lopenfile, sfiletext close lopenfile 

also want sum things has been changed. can me that?

i guess want remove diacretics string, accents or umlauts. use method efficient since it's using stringbuilder:

public shared function removediacritics(s string) string     dim normalizedstring string = s.normalize(normalizationform.formd)     dim stringbuilder new stringbuilder()      each c char in normalizedstring         if charunicodeinfo.getunicodecategory(c) <> unicodecategory.nonspacingmark             stringbuilder.append(c)         end if     next      return stringbuilder.tostring() end function 

[ remember add imports system.text top of code file ]

but note convert ü u(as desired) isn't correct. should "translate" german umlauts in following way: ü=ue,ä=ae, ö=oe. related

you'd call above method f.e. in way:

dim text string = file.readalltext(sfilename) dim newtext string = removediacritics(text) file.writealltext(sfilename, newtext) 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -