rss
logo

I provide consulting and custom development for Natural Language Processing, Information Extraction and Search solutions.Self Picture


 learn more   get in touch 

Logo - I Build Search
Apr 07
2006

Implementing Emoticons in C# digg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public string Emotify(string inputText)
{
	#region Create Emote hashtable
	Hashtable htEmotes = new System.Collections.Hashtable(100);
	htEmotes.Add(":))", "21");
	htEmotes.Add(":)>-", "67");
	htEmotes.Add(":)", "1");
	htEmotes.Add(":-)", "1");
	htEmotes.Add(":((", "20");
	htEmotes.Add(":(", "2");
	// Add other Yahoo emotes
	#endregion
 
 
	StringBuilder sb = new StringBuilder(inputText.Length);
 
	for (int i = 0; i < inputText.Length; i++)
	{
		string strEmote = string.Empty;
		foreach (string emote in htEmotes.Keys)
		{
			if (inputText.Length - i >= emote.Length &&
				emote.Equals(inputText.Substring(i, emote.Length),
				StringComparison.InvariantCultureIgnoreCase))
			{
				strEmote = emote;
				break;
			}
		}
 
		if (strEmote.Length != 0)
		{
			sb.AppendFormat("<img src='images/{0}.gif' alt='{1}' />", htEmotes[strEmote], strEmote);
			i += strEmote.Length - 1;
		}
		else
		{
			sb.Append(inputText[i]);
		}
	}
	return sb.ToString();
}

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Latest Articles

Apr
07

Palindromic sub-sequences in python

This bit of python code returns all palindromic subsequences in the input string.

[Read More]
Feb
19

Join a list of integers in Python

How do you run a string join on a list of integers in Python? After googling for about 10 mins, I gave up and did this. I am sure there is a better way of doing it!

[Read More]

Featured Projects

Document Tagger

Document Tagger

DocTagger lets you automatically classify text documents. Use this as a starting point to write apps that can sort through volumes of unorganized data.

[Read More]

NLP classes for PHP

NLP classes for PHP

This is an ongoing project to develop a set of classes for Natural Language Processing. Some code would be ported from the NLTK project.

[Read More]

This page and its contents are copyright © 2010, Pravin Paratey.