如何遍历NSString的字符 [英] How to iterate through the characters of an NSString

查看:94
本文介绍了如何遍历NSString的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSString *myStrings = @"abcdefghijklmnopqrstuvwxyz";

如何在Objective-C for循环中迭代每个字母(a,b,c,d,e等)?

How could I iterate each of the letters (a, b, c, d, e, etc..) in an Objective-C for loop?

推荐答案

一种方法是使用简单的for循环:

One way is to use a simple for-loop:

for (NSInteger charIdx=0; charIdx<myStrings.length; charIdx++)
    // Do something with character at index charIdx, for example:
    NSLog(@"%C", [myStrings characterAtIndex:charIdx]);

这篇关于如何遍历NSString的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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