开发者

Accept different encoding as input to form

开发者 https://www.devze.com 2023-04-06 04:09 出处:网络
I have a webpage with a form that accepts userinput that when submitted is used as content for a text file – the simplified application flow is:

I have a webpage with a form that accepts userinput that when submitted is used as content for a text file – the simplified application flow is:

1) User enters text and presses submit

2) Webpage gets template from filesystem and replaces some of the content of the file with the userinput

3) File is stored.

Now the problem is that the form can be used by people with different nationalities and written language, and if the user enters for example Chinese text, into the form, I want the Chinese characters to be written to the file. As I understand it I need to know the encoding for the content – is there any way to get this from th开发者_运维百科e form, or do you have another idea to get around this?

Best regards (or as some users would input 最好的問候)

Michael


In ASP.Net This should already work pretty much exactly as you describe it:

  1. The browser allows the user to enter some text and submits it to the web server using a suitable encoding. The ASP.Net framework handles the encoding for you and just gives you a standard .Net string.
  2. As long as the templating itself is done using standard .Net strings you shouldn't need to worry about the encoding when doing string manipulation - the .Net framework handles the encoding internally and exposes the characters represented independently of encoding.
  3. When saving the file you just need to make sure you choose a suitable encoding. UTF-8 will do just fine and is most likely the encoding that the .Net framework will choose unless you explicitly specify another encoding.

Have you tried this yet? If so what goes wrong?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号