如何从字符串中删除特定的单词? [英] how to remove particular words from strings?

查看:60
本文介绍了如何从字符串中删除特定的单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NSString * str,值@@我喜欢编程和游戏".我必须删除我"喜欢"&我的字符串中的和",因此它看起来应该像是编程游戏"

I have an NSString *str, having value @"I like Programming and gaming." I have to remove "I" "like" & "and" from my string so it should look like as "Programming gaming"

任何想法,我该怎么做?

How can I do this, any Idea?

推荐答案

NSString *newString = @"I like Programming and gaming.";
NSString *newString1 = [newString stringByReplacingOccurrencesOfString:@"I" withString:@""];
NSString *newString12 = [newString1 stringByReplacingOccurrencesOfString:@"like" withString:@""];
NSString *final = [newString12 stringByReplacingOccurrencesOfString:@"and" withString:@""];

分配给错误的字符串变量,现在可以编辑

Assigned to wrong string variable edited now it is fine

NSLog(@"%@",final);

输出:游戏编程

这篇关于如何从字符串中删除特定的单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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