标题翻译
How to do URL encoding of value which is already in %
问题
用户输入: ABC!123%C56
期望输出: ! 和 % 符号应该被编码,但是 ! 符号被编码了,而 % 符号没有被编码,因为 %C 已经是其他某个符号的值。请提供解决方案,如何对 % 符号进行编码。
英文翻译
I have to ask input from user and then do encoding for input.
user input : ABC!123%C56
expected output: ! and % symbol should be encoded but ! symbol got encoded and % symbol didn't encode because %C is already value of some other symbol.please suggest solution how to use encoding with % symbol.
答案1
得分: -1
你可以匹配用户输入的符号中是否包含%
。如果它包含%
,你可以将%
替换为一个特殊符号(通常用户不会输入的符号)。尽量避免选择用户常用的符号。例如,<p>
代表百分号。我认为<p>
符号很少使用。如果需要解码它,将<p>
替换为%
。
> 例如:ABC!123%C56 --> ABC!123<p>C56
英文翻译
You can match whether%
is contained in the symbol entered by the user. If it contains %
, you can replace%
with a special symbol (the symbol that the user does not normally enter). Try to avoid selecting the symbols that users will use. For example, <p>
stands for percent. I think the <p>
symbol is rarely used. If you need to decode it, replace <p>
with %
.
> for example: ABC!123%C56 --> ABC!123<p>C56
专注分享java语言的经验与见解,让所有开发者获益!
评论