中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

字符串分割小例子

發布時間:2020-07-24 09:17:09 來源:網絡 閱讀:265 作者:iSanny 欄目:開發技術
一個反向輸出字符串的例子,不用componentsSeparatedByString去實現以空格字符分割字符串然后反向輸出:


#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

        @autoreleasepool {
                
                // insert code here...
                //NSLog(@"Hello, World!");
                NSString *a =[[NSString alloc] initWithFormat:@"I am a good person\n"];
                NSMutableString *letters = [NSMutableString stringWithFormat:@""];
                //NSInteger t = 0;
                for (NSInteger i = a.length-1;i>=0; i--)
                {
                        if([a characterAtIndex:i]==' ')
                        {
                                NSString *temp = [a substringWithRange:NSMakeRange(i+1,a.length-i-1)];
                                //NSLog(@"%@",temp);
                                for(NSInteger j=0;j<temp.length;j++)
                                {
                                        if([temp characterAtIndex:j]==' ' || [temp characterAtIndex:j]=='\n')
                                        {NSString *temp2= [temp substringWithRange:NSMakeRange(0, j)];
                                                [letters appendString:temp2];
                                                [letters appendString:@" "];
                                                //NSLog(@"%@",temp2);
                                                break;
                                        }
                                }
                        }
                        if(i==0)
                        {
                                [letters appendString:[a substringWithRange:NSMakeRange(0,i+1)]];
                        }
                }
        NSLog(@"%@",letters);
        }
        
        return 0;
}

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

炎陵县| 集安市| 大宁县| 乐清市| 金坛市| 昌黎县| 墨竹工卡县| 依安县| 武隆县| 高邑县| 通许县| 莫力| 荥阳市| 洪洞县| 涡阳县| 乌什县| 博野县| 芜湖市| 台前县| 澄江县| 仲巴县| 大理市| 永善县| 营山县| 资阳市| 株洲县| 如东县| 阿勒泰市| 祁连县| 镇雄县| 尤溪县| 新竹市| 巴青县| 庆元县| 高邮市| 黔西| 伊川县| 沧源| 七台河市| 霍城县| 克东县|