扫描代码中添加了括号

问题描述 投票:0回答:2

当我的条形码扫描仪扫描代码时,它会在开头添加 ],在结尾添加 [。我该如何改变这个?

barcode-scanner
2个回答
1
投票

不幸的是,它是条码扫描仪设置参数,并且因特定条码阅读器而异。您将需要条码扫描仪的文档/SDK。许多条码扫描仪只需扫描设置条码即可设置前导/尾随字符。


0
投票

您可能可以做一件事,我们可以将其视为我们代码库中的本地管理。

    func removeAllUnusedSpacesAndTabsCharacters(strBarCode: String) -> String {
    var strCode = strBarCode.replacingOccurrences(of: "\r", with: "")
    strCode = strCode.replacingOccurrences(of: " ", with: "")
    strCode = strCode.replacingOccurrences(of: "  ", with: "")
    strCode = strCode.replacingOccurrences(of: "\r\n", with: "")
    strCode = strCode.replacingOccurrences(of: "\t", with: "")
    strCode = strCode.replacingOccurrences(of: "\n", with: "")
    strCode = strCode.replacingOccurrences(of: "^\\s*", with: "")
    strCode = strCode.trimmingCharacters(in: .whitespacesAndNewlines)
    return strCode
}

当条形码扫描并显示在您的标签或字段上时,在设置之前准备一个函数并放入上面的代码片段。

这将删除 [ 括号。

© www.soinside.com 2019 - 2024. All rights reserved.