sqlite3特殊字符处理

2022-02-07阅读(2945)评论(0)牵着狗狗看MM

苏州实时公交查询

操作sqlite3数据库的时候,一些特殊字符需要进行转义处理,直接上代码

/**
 * @description 转义sqlite3中的特殊字符
 * @param str
 * @returns
 */
replaceSpecialCharacter(str: string) {
    str = str.replaceAll('/', '//')
    str = str.replaceAll('[', '/[')
    str = str.replaceAll(']', '/]')
    str = str.replaceAll('%', '/%')
    str = str.replaceAll('&', '/&')
    str = str.replaceAll('_', '/_')
    str = str.replaceAll('(', '/(')
    str = str.replaceAll(')', '/)')
    str = str.replaceAll("'", "''")
    return str
}

 

赞(0)
转载请注明来源:Web前端(W3Cways.com) - Web前端学习之路 » sqlite3特殊字符处理
分享到: 更多 (0)