我正在聊天应用程序中处理表情符号。当有人向我发送表情符号时,我收到了这种格式的消息:- 你好...(担心)你好吗(快乐)?
(worried) and (happy) are considerd as emoji
arremojivalue=[[NSArray alloc]initWithObjects:@"(worried)",@"(sad)",@"(bandit)",@"(wink)",@"(surprised)",@"(smirking)",@"(laugh)",@"(cool)",@"(stoned)",@"(smile)",@"(nerd)",@"(happy)",@"(evil-grin)",@"(tongue)",@"(lips-sealed)",@"(GIF)",@"(dull)", nil];
当我收到消息(字符串)时,我如何检查它是否包含来自 arremojivalue 的上述单词。我想将消息字符串中的(担心)和(快乐)词替换为“表情符号”。
我试过这个:-
NSString *stremoji;
stremoji=[NSString stringWithFormat:@"%@",arremojivalue];
if ([message containsString:stremoji])
{
message= [message stringByReplacingOccurrencesOfString:stremoji
withString:@"(emoji)"];
cell.textLabel.text=message; //@"Emoji arrived";
}
首先请回答我如何从字符串中删除这些词(担心)(快乐)到“表情符号”。
之后我想将那些“表情符号”替换为 UIWebview 以显示 GIF 表情符号。
谢谢
最佳答案
试试这个
NSArray *arremojivalue=[[NSArray alloc]initWithObjects:@"(worried)",@"(sad)",@"(bandit)",@"(wink)",@"(surprised)",@"(smirking)",@"(laugh)",@"(cool)",@"(stoned)",@"(smile)",@"(nerd)",@"(happy)",@"(evil-grin)",@"(tongue)",@"(lips-sealed)",@"(GIF)",@"(dull)", nil];
//
NSString *message = @"Hello...(worried) how are you(happy)?";
for (NSString *emoji in arremojivalue) {
if ([message containsString:emoji]){
message = [message stringByReplacingOccurrencesOfString:emoji withString:YourEmojiValue];//value for (worried) = @":)"
}
}
NSLog(@"message updated:%@",message);
//你的问题的第二部分
NSDictionary *emojiDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@":)",@"(worried)",
@"(:D)",@"(smile)",
nil];
NSString *message = @"Hello...(worried) how are you(smile)?";
for (NSString *emojiKey in emojiDictionary.allKeys) {
if ([message containsString:emojiKey]){
message = [message stringByReplacingOccurrencesOfString:emojiKey withString:[emojiDictionary valueForKey:emojiKey]];
}
}
NSLog(@"message updated:%@",message);
关于ios - 用图像替换字符串字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33079996/