// if((btn.currentTitle == answerBtn.currentTitle) && btn.hidden == YES)
// 字符串相等比较 不要直接比,这样比的是指针,不是指针指向的数据
if([btn.currentTitle isEqualToString:answerBtn.currentTitle] && btn.hidden == YES)

NSString *strA = [NSString stringWithFormat:@"a"];

NSString *strB = [NSString stringWithFormat:@"b"];

if( strA == strB)

    NSLog(@"A is equal to B");

    else

    NSLog(@"A is not equal to B");

运行这段code, 在console 上的输出是: A is not equal to B

代码做些改动, 将 strA 与strB 设为相等。

NSString *strA = [NSString stringWithFormat:@"a"];

NSString *strB = [NSString stringWithFormat:@"a"];

if( strA == strB)

    NSLog(@"A is equal to B");

    else

    NSLog(@"A is not equal to B");

运行这段code ,在console上的输出仍然是 A is not equal to B 。

这是为什么呢 ?问题出在 字符串对比的语句上。

if ( strA == strB) // 这个strA, strB 是指针, 虽然字符串的内容是相同的, 但指向字符串的 指针肯定是不同的, 也不能相同啊。 (为了更好地理解字符串,需要弄清楚 指针的概念。 内存的分配。 )

// 错误:if( strA == strB)

// 正确: if ([strA isEqualToString:strB])

iOS SDK 本身 也提供了 字符串对比的方法: isEqualToString:

判断字符串是否相等 isEqualToString:的更多相关文章

  1. iOS 判断字符串是否为空

    写一个字符串的扩展,实现判断字符串是否为空- (BOOL) isBlankString { if ([self isEqualToString:@"(null)"]) { retu ...

  2. C# 判断字符串是否是int/double

    using System.Text.RegularExpressions; /// <summary> /// 判断字符串是否是int/double /// </summary> ...

  3. C#判断字符串是否是数字

    /// <summary> /// 判断字符串是否是数字 /// </summary> public static bool IsNumber(string s) { if ( ...

  4. JS判断字符串长度的5个方法

    这篇文章主要介绍了JS判断字符串长度的5个方法,并且区分中文和英文,需要的朋友可以参考下 目的:计算字符串长度(英文占1个字符,中文汉字占2个字符)   方法一:    代码如下: String.pr ...

  5. C++ 判断字符串是否全是数字

    在实际的工作中,需要提取程序中的字符串信息,但是程序中经常将一些数字当做字符串来进行处理,例如表盘的刻度信息,这时候就需要判断字符串是否全为数字,来进行真正意义上的字符串提取.下面介绍了判断字符串是否 ...

  6. Shell判断字符串包含关系的几种方法

    现在每次分析网站日志的时候都需要判断百度蜘蛛是不是真实的蜘蛛,nslookup之后需要判断结果中是否包含“baidu”字符串 以下给出一些shell中判断字符串包含的方法,来源程序员问答网站 stac ...

  7. Android 判断字符串是否为空

    TextUtils.isEmpty(str) 可以判断字符串是否为null或者"",当是的时候为true,否的时候为false

  8. 用递归法判断字符串A中包含多少个字符串B

    string类提供了判断字符串B在字符串A中首次(或最后)出现的Index的方法,但有时候需要判断B在A中出现了多少次. 为此想了一个算法. public static void CountIndex ...

  9. PHP判断字符串中是否包含指定字符串,支持中文哦

    RT,随手写的 /** * 判断字符串中是否包含指定字符串 * @var source 源字符串 * @var target 要判断的是否包含的字符串 * @return bool */ functi ...

随机推荐

  1. Python中关于字符串的问题

    在Python里面,字符串相加经常会出现'ascii' codec can't decode byte 0xe7 in position 0: ordinal not in range(128)这样的 ...

  2. SCNU 2015ACM新生赛决赛【F. Oyk闯机关】解题报告

            题目大意:一个$N$$\times$$N$的阵列,每个格子有$X_{ij}$个调和之音,若每次只能选择走右边或下边,从左上角出发走到右下角,问最多能收集到多少个调和之音?       ...

  3. Python 【第十一章】 Django模版

    1.直接传值 urls.py """mysite URL Configuration The `urlpatterns` list routes URLs to view ...

  4. [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值

    Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...

  5. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  6. [LeetCode] Permutations 全排列

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  7. Intellij IDEA 快捷键

    Ctrl+Shift + Enter,语句完成 "!",否定完成,输入表达式时按 "!"键 Ctrl+E,最近的文件 Ctrl+Shift+E,最近更改的文件 ...

  8. 用vue.js学习es6(一):基本工具及配置

    一.工具: sublime,node.js,npm 1.安装sublime 的es6插件: (1).在sublime中按Ctrl+`调出console (2).粘贴以下代码到底部命令行并回车(subl ...

  9. How to Disable Strict SQL Mode in MySQL 5.7

    If your app was written for older versions of MySQL and is not compatible with strict SQL mode in My ...

  10. shell-for循环

    sheel语言for循环格式 for var in item1 item2 ... itemN do command1 command2 ... commandN done 案例1 #!/bin/ba ...