为什么不是我的字符串表示,当他们作为平等? [英] Why aren't my Strings showing as equal when they are?

查看:121
本文介绍了为什么不是我的字符串表示,当他们作为平等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作在Eclipse中做一个Android应用程序。目前我有两个字符串,我需要检查是否相等与否,问题是字符串相等,但它正显示出他们不要这实在是令人沮丧的我。

I am currently working in Eclipse making a Android App. At the moment I have two Strings and I need to check if they are equal or not, the problem is the Strings are equal but it is showing them not to be which is really frustrating me.

    if (newSource.equals(source)) {
        Log.d("Equal:", "Strings are equal");
    }
    else {
        Log.d("Not Equal: ", "Strings aren't equal");     
    }

当我运行这一点,只是打印在日志猫的字符串不相等。我已经印在日志猫两个字符串,以确定它们是100%相同,他们都是。我只是想知道如果任何人能看到我的code错误? 谢谢

When I run this it just prints in the log cat that the strings aren't equal. I have printed both strings in the log cat to check that they are 100% equal which they are. I was just wondering if any one could see an error in my code? Thanks

推荐答案

使用修剪()将eleminate空间,如果任何

Use trim() which will eleminate spaces if any

if ((newSource.trim()).equals(source.trim()))

这篇关于为什么不是我的字符串表示,当他们作为平等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆