Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java中字符串和HTML的比较_Java_Html_String Comparison - Fatal编程技术网

Java中字符串和HTML的比较

Java中字符串和HTML的比较,java,html,string-comparison,Java,Html,String Comparison,我试图比较一行HTML和一个包含变量的HTML字符串。然而,我的方法在应该返回TRUE时却一直返回FALSE //textLineToCheck contains the HTML string public static boolean checkWhiteList(String textLineToCheck, String nameOfPerson) { textLineToCheck=textLineToCheck.trim(); textLineToCheck=tex

我试图比较一行HTML和一个包含变量的HTML字符串。然而,我的方法在应该返回TRUE时却一直返回FALSE

//textLineToCheck contains the HTML string

public static boolean checkWhiteList(String textLineToCheck, String nameOfPerson) {
    textLineToCheck=textLineToCheck.trim();
    textLineToCheck=textLineToCheck.toLowerCase();
    boolean isOfValue=false;
    if (textLineToCheck.equals("<h2 class='altResource'>"+nameOfPerson+"</h2>")) {
        isOfValue=true;
    }
    return isOfValue;
} //end checkWhiteList()
//textLineToCheck包含HTML字符串
公共静态布尔检查白名单(字符串textLineToCheck,字符串nameoperson){
textLineToCheck=textLineToCheck.trim();
textLineToCheck=textLineToCheck.toLowerCase();
布尔值=假;
if(textLineToCheck.equals(“+nameOfPerson+”)){
值=真;
}
返回值;
}//结束检查白名单()

我认为问题在于在
文本行中使用小写字母来检查

假设您有
textLineToCheck=abc”

nameOfPerson = "abc"
当您执行
textLineToCheck=textLineToCheck.toLowerCase();

会的
textLineToCheck=abc”
(注意
altresource
中的小
r

若你们把它和人的名字相比较,你们就是在比较

textLineToCheck=abc“

abc”


这显然会返回
false

我认为问题在于在
textLineToCheck

假设您有
textLineToCheck=abc”

nameOfPerson = "abc"
当您执行
textLineToCheck=textLineToCheck.toLowerCase();

会的
textLineToCheck=abc”
(注意
altresource
中的小
r

若你们把它和人的名字相比较,你们就是在比较

textLineToCheck=abc“

abc”


这显然会返回
false

问题出在altResource中的一个大R中。您正在将它与小写字符串进行比较。

问题在于altResource中的大R。您正在将其与小写字符串进行比较。

注意:nameOfPerson是小写的,似乎HTML代码正在删除。我向你保证它是准确的。你能给我们
textLineToCheck
的值吗?你也可以不使用
isOfValue
而返回表达式
textLineToCheck.equals(“+nameoperson+”)
注意:nameoperson是小写的。HTML代码似乎正在被删除。我向你保证它是准确的。你能不能给我们
textLineToCheck
的值,而不是使用
isOfValue
你也可以返回表达式
textLineToCheck.equals(“+nameoperson+”)
这看起来像是原因。是的,这看起来像原因。