gpt4 book ai didi

java - 对于同一个字符串,SQLite 的长度是否会返回与 Java 的长度方法不同的值?

转载 作者:行者123 更新时间:2023-12-03 11:18:46 25 4
gpt4 key购买 nike

给一个相同的String数据

  • SQLite 执行 length计算其TEXT柱子。
  • TEXT列被读入(使用 Android Room 数据库)Java 字符串,然后 Java 执行 String.length()

  • 这些有没有可能产生2个不同的值(value)?
    我用英文和非英文字符做了一个粗略的测试。两者产生相同的值。
    但是,我不确定我是否错过了任何边缘情况?

    最佳答案

    由于您正在寻找边缘情况...
    来自 SQLite 的 Built-In Scalar SQL Functions :

    length(X)
    For a string value X,
    the length(X) function returns the number of characters (not bytes) in X
    prior to the first NUL character. (emphasis mine)
    Since SQLite strings do not normally contain NUL characters,
    the length(X) function will usually return the total number of characters in the string X....


    所以,SQLite,对于:
    SELECT LENGTH('a' || CHAR(0) || 'b')
    将返回 1 ,
    但是Java,用于:
    String s = "a" + Character.toString('\0') + "b";
    System.out.println("" + s.length());
    将返回 3 .

    关于java - 对于同一个字符串,SQLite 的长度是否会返回与 Java 的长度方法不同的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64558317/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com