Click here to Skip to main content
Licence CPOL
First Posted 28 Jun 2003
Views 70,186
Downloads 1,813
Bookmarked 44 times

Display Emoticons on an ASP.NET Webpage

By | 28 Jun 2003 | Article
Code to replace emoticons within a string by their HTML-images.

Sample Image - AspNetEmoticons.jpg

Introduction

Inspired by a question in the CodeProject's ASP.NET forum, I decided to quick-assemble some code for displaying emoticons within a web page.

Displaying emoticons is the task of replacing text-fragments within a string (e.g. ":-)", ":-(" ) by some HTML code that displays an image (e.g. Laughing smiley and Crying smiley). So simple spoken, the whole project is a nicely encapsulated string-replace that hopefully is useful to the guy who asked the question, as well as to other programmers.

Description

The project contains a ready-to-compile-and-run Visual Studio 2003 solution with one Web Form web page Index.aspx to test out the functionality. The effective code is contained within the class Emoticon in the file Emoticons.cs.

The class Emoticon has two static members. The first is:

/// <summary>
/// Returns a collection of all available emoticons.
/// </summary>
public static Emoticon[] All

to get a collection of all available emoticons. Within this member, the actual references to the image files are created, so if you want to add your own emoticons, you must place the news images within the Emoticons subfolder and modify this member to "know" the new emoticons.

The second static member is the function:

/// <summary>
/// Returns a string with all emoticons replaced by their images.
/// </summary>
public static string Format( string input )

This member function does the core replacement of an input string with the HTML-code to display the the emoticons. Any occurrence of the emoticons registered within All are replaced and returned by this function.

Using the code

To use the code, simply call the Format function like this:

string text = Emoticon.Format( "Some text with a smiley :-) emoticon." );

History

  • 2003-06-29: Article created

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Uwe Keim

Chief Technology Officer
Zeta Producer Desktop CMS
Germany Germany

Member

Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He is also teached programming to students at the local university.
 
In his free time, he does climbing, running and mountain biking. You can watch him most of the day (and probably night) programming.
 
Some cool, free software from us:
 
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email
Some random fun stuff in German


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalwww.dotnetobject.com Pinmemberfarooq148200818:29 8 Aug '11  
GeneralNice work!!! Pinmembersimpa2:04 29 Sep '10  
GeneralThx PinmemberMorten Jørgensen10:40 1 Feb '10  
GeneralEmoticon.Format in a bound dataGrid Pinmembergadgetfbi13:45 16 Jul '03  
GeneralRe: Emoticon.Format in a bound dataGrid PinsitebuilderUwe Keim3:33 20 Jul '03  
GeneralPlease be patient... PinsitebuilderUwe Keim8:54 29 Jun '03  
GeneralRe: Please be patient... PinsitebuilderUwe Keim9:02 29 Jun '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 29 Jun 2003
Article Copyright 2003 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid