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

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();
}

Latest Articles

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]
Jan
21

Writing a spider in 10 mins using Scrapy

I came across Scrapy a few days back and have grown to really love it. This tutorial will illustrate how you can write a simple spider using Scrapy to scrape data off Paul Smith. All this in 10 minutes. [Read More]

Featured Projects

Deebot

Deebot

Deeb0t is an IRC chat bot capable of making meaningful conversation with other users. It also responds to commands issued by its owner.

[Read More]

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]

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