当前位置:网站首页>Kotlin SQLite URL escape character (escape) (I)
Kotlin SQLite URL escape character (escape) (I)
2022-07-18 15:04:00 【laoyouzhazi】
Kotlin SQLite URL Escape character (Escape)( One )
Preface
In the use of SQLite preservation URL Address time , It is easy to appear some characters that need escape , Like single quotes (')、 Percent sign (%) wait . Before saving data sheet records , It is safer to deal with special characters before saving . Generally speaking , Handle “ special ” The escape character of , It is to transform the target string into a standard format . such as , Can be converted to URL encode Encoding or Base64 code , Decode when you need to use the source string . This type of encoding is a permutation encryption , This will not destroy the integrity of the source data and good performance at the same time , It can also structure data , Make the converted data more organized 、 Easy to handle and save . To simplify the description , What is mainly mentioned here is URL encode Coding method .
URL Encoding
URL Encoding will convert some special characters except letters and numbers into Percent sign + 16 Hexadecimal Numbers The format of ( Such as ,%2A).URL Encoding is also valid for converting Chinese characters .
flow chart
URL Encode
import java.net.URLEncoder
import kotlin.text.Charsets
fun encode(url: String?): String?{
return URLEncoder.encode(url, Charsets.UTF_8.toString())
}
Escape
fun escape(encodedUrl: String?): String?{
return encodedUrl?.replace("%", "/%")?.replace("*", "/*")?.replace("'", "/'")?.replace("_", "/_") } Unescape
fun unescape(escapedUrl: String?): String?{
return escapedUrl?.replace("/%", "%")?.replace("/*", "*")?.replace("/'", "'")?.replace("/_", "_") } URL Decode
import java.net.URLDecoder
fun decode(unescapedUrl: String?): String?{
return URLDecoder.decode(unescapedUrl, Charsets.UTF_8.toString())
}
note
Use Base64 Encoding special characters that need to be replaced URL Less coding . Both are replacement encryption , There is no essential difference , It is estimated that the efficiency will be different only when the order of magnitude is large .
边栏推荐
- [communication] [1] amplitude modulation, frequency modulation, double sideband and single sideband, IQ and PSK and QAM - must sampling meet Nyquist theorem
- The secret of black industry that the risk controller cannot know
- Go syntax - deferred call defer
- 【成像】【7】太赫兹光学——光学元件和子系统
- Wechat selection and voting of finished works of applet graduation project (7) mid term inspection report
- C library function - sscanf() usage
- Wechat selection and voting of finished works of applet graduation project (6) opening defense ppt
- 函数栈帧(值得收藏)
- Conditional ternary operator...
- Vulnhub-DC6学习笔记
猜你喜欢
随机推荐
ACL 2022 | argument pair extraction based on reading comprehension
AcWing 3433. Eat candy recursively | find rules
学习路之PHP--post获取不到请求数据
小程序毕设作品之微信评选投票小程序毕业设计(7)中期检查报告
2022t elevator repair operation certificate examination questions and online simulation examination
函数栈帧(值得收藏)
(CVPR-2022)用于改进步态识别的拉格朗日运动分析和视角嵌入
分布式笔记(01)— 分布式 CAP 理论及原理
【通信】【1】幅度调制,频率调制,双边带与单边带,IQ与PSK与QAM——采样一定要满足奈奎斯特定理吗
Vulnhub-dc6 learning notes
小程序毕设作品之微信评选投票小程序毕业设计(5)任务书
The secret of black industry that the risk controller cannot know
Wwdc22 - Apple privacy technology exploration
AcWing 3433. 吃糖果 递推|找规律
AcWing 3619. Date date processing
06-GuliMall 基础CRUD功能创建
Variables in shell scripts
AcWing 3540. Binary search tree binary sort tree BST
AcWing 3540. 二叉搜索树 二叉排序树 BST
HMM & MEMM & CRF









