gpt4 book ai didi

java - 什么可能导致 String.charAt(0) 不打印任何内容,并且字符类型为 "16"?

转载 作者:行者123 更新时间:2023-12-02 00:30:02 25 4
gpt4 key购买 nike

有人知道这里会发生什么吗?

第一个 block 显示了我通常期望看到的内容 - 字符串的第一个字符位于索引“0”中,“问题”字符串被注释掉,被完全相同的东西替换,但之前从未运行过。

public void finderTest(){
String theDoc = "Hello, I want this to work, and work well! Do you think it will work, and if not, why not?";
//String wordOne = "‭abc"; // old, pre-used string, used to hold a comma.
String wordOne = "abc";// new, never run before with a comma
String wordTwo = "and";
System.out.println("Type of character at index '0' in theDoc: "+Character.getType(theDoc.charAt(0)));
System.out.println("Character at index '0' in theDoc: "+theDoc.charAt(0));
System.out.println();
System.out.println("All of wordOne: "+"'"+wordOne+"'");
System.out.println("Type of character at index '0' in wordOne: "+Character.getType(wordOne.charAt(0)));
System.out.println("Character at index '0' in wordOne: "+wordOne.charAt(0));
System.out.println();
System.out.println("Type of Character at index '0' in wordTwo: "+Character.getType(wordTwo.charAt(0)));
System.out.println("Character at index '0' in wordTwo: "+wordTwo.charAt(0));
}

输出:

/*
Type of character at index '0' in theDoc: 1
Character at index '0' in theDoc: H

All of wordOne: 'abc'
Type of character at index '0' in wordOne: 2 // okay
Character at index '0' in wordOne: a // okay

Type of Character at index '0' in wordTwo: 2
Character at index '0' in wordTwo: a
*/

第二个 block 将“new”字符串注释掉,“wordOne”的第一个字符什么也没有。它不是空字符或换行符。我一直在使用该变量在“theDoc”中查找逗号...但是当我运行它时,索引“0”没有包含任何内容,而索引 1 中有逗号。如果我复制并粘贴该字符串,问题仍然存在。但是,注释掉/删除它可以解决该问题。

    public void finderTest(){
String theDoc = "Hello, I want this to work, and work well! Do you think it will work, and if not, why not?";
String wordOne = "‭abc"; // now running old string, used to hold comma
//String wordOne = "abc";
String wordTwo = "and";
System.out.println("Type of character at index '0' in theDoc: "+Character.getType(theDoc.charAt(0)));
System.out.println("Character at index '0' in theDoc: "+theDoc.charAt(0));
System.out.println();
System.out.println("All of wordOne: "+"'"+wordOne+"'");
System.out.println("Type of character at index '0' in wordOne: "+Character.getType(wordOne.charAt(0)));
System.out.println("Character at index '0' in wordOne: "+wordOne.charAt(0));
System.out.println();
System.out.println("Type of Character at index '0' in wordTwo: "+Character.getType(wordTwo.charAt(0)));
System.out.println("Character at index '0' in wordTwo: "+wordTwo.charAt(0));
}

输出:

/*  
Type of character at index '0' in theDoc: 1
Character at index '0' in theDoc: H

All of wordOne: '‭abc'
Type of character at index '0' in wordOne: 16 // What does this mean?
Character at index '0' in wordOne: ‭ // where is the a? (well, its in wordOne index '1'... but why??)

Type of Character at index '0' in wordTwo: 2
Character at index '0' in wordTwo: a
*/

java中的逗号或符号是否会导致这样的问题?我尝试使用字符数组,清理工作区来重新构建所有内容,但没有任何改变……当某些克是“,和”之类的东西时,这对于在句子中查找“ngram”索引是一个巨大的问题。昨晚某个时候,它可以工作,然后突然开始不工作。我很困惑。

有什么想法吗?

最佳答案

我尝试将您的示例粘贴到 Eclipse 中,它告诉我:

Some characters cannot be mapped using "Cp1252" character encoding.

并向我指出字符串中的第一个字符:

String wordOne = "abc";

"a 之间似乎有一个隐藏(不可打印)字符。

关于java - 什么可能导致 String.charAt(0) 不打印任何内容,并且字符类型为 "16"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9251942/

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