Processing UTF-8-encoded content in Lotus script

Source: Internet
Author: User
Tags html form submit
Recently, we need to complete a Lotus Domino-based website. Due to mixed language problems, the website encoding tone is set to UTF-8, and some of them need to use the lotus scprit proxy to directly receive data from the HTML form submit. I used to try to avoid this problem. At that time, there was no time. In order to catch up with the progress, I had to do this. I decided to renew the project to see if my teeth were okay. Goal: Decode UTF-8 form data in Lotus script agent. Google, Baidu plus IBM Lotus forum, a search, four or five ready-made Code , The test does not have a right, want to be lazy do not :( change the idea, query UTF-8 coding rules, Baidu found a description about the UTF-8, very good, finally understand the character encoding to UTF-8 encoding conversion rules. The original UTF-8 encoding is the character encoding through a conversion rule into 1 ~ 6-byte encoding. The browser converts multi-byte characters and a part of Single-character characters in form into this encoding, connects them to other single-byte characters, and replaces the spaces with "+, it becomes the string parameter received in the Lotus agent. Because the uchr () function in Lotus script can only convert two-byte characters at most, the 3-and 4-byte characters are not converted and are retained in the original string. Function utf8decode (S as string) as string
Dim I as integer
Dim TMP as string
Dim C as string
TMP = ""
For I = 1 to Len (s)
C = mid $ (S, I, 1)
If C = "+" then
C = ""
Elseif c = "%" then
C = mid $ (S, I + 1, 2)
If (Val ("& H" & C)> = 0) and (Val ("& H" & C) <= Val ("& h7f") then
C = uchr $ ("& H" & C)
I = I + 2
Elseif (Val ("& H" & C)> = Val ("& hc0") and (Val ("& H" & C) <= Val ("& HDF") then
C = right (bin $ (Val ("& H" & Mid $ (S, I + 1, 2), 5)
C = C & right (bin $ (Val ("& H" & Mid $ (S, I + 4, 2), 6)
C = uchr $ ("& B" & C)
I = I + 5
Elseif (Val ("& H" & C)> = Val ("& he0") and (Val ("& H" & C) <= Val ("& Hef") then
C = right (bin $ (Val ("& H" & Mid $ (S, I + 1, 2), 4)
C = C & right (bin $ (Val ("& H" & Mid $ (S, I + 4, 2), 6)
C = C & right (bin $ (Val ("& H" & Mid $ (S, I + 7, 2), 6)
C = uchr $ ("& B" & C)
I = I + 8
Else
C = mid $ (S, I, 3)
I = I + 2
End if
End if
TMP = TMP + c
Next I
Utf8decode = TMP
End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.