View Full Version : smilies help


Lotus
06-26-2003, 07:48 PM
Um, i made my own messageboard but i can't get the smilies to work or appear. I go the images and everything but it just won't show up. Can anyone here help me. Thanks!

amicus
06-26-2003, 08:27 PM
how did you make it? i made my own too and it works fine. you have to parse through the user entry then look for the ':', ')' and what ever else there is :) then replace those with the 'img' tag.

don't put it into the database with the 'img' tag but do the parsing after you've pulled it out of the database.

Lotus
06-27-2003, 12:40 AM
can you show an example? I mean, actually type it out so I'll have a visual? thanks.

adrielle
06-27-2003, 11:34 AM
wow, can you guys teach me how??? *sorry, i'm going off topic*

amicus
06-27-2003, 05:04 PM
this is written in java so i'm not sure if it'll work for you. anyhoo i'm sure you'll get some ideas on how to make one. it's pretty simple just parse through the user entry looking for the ':' and ')'. once you find it replace it with the 'img' tag :)

after the 'hee, hee' is a smiley ': )' without the space. it just switch to the image.

String userText = "this is a test hee, hee :)";

StringBuffer stringBuffer = new StringBuffer();
boolean isEmoticon = false;

// Iterate the text and append to stringbuffer
for ( int i = 0; i < userText.length(); i++ ) {
char currentChar = userText.charAt( i );

// If the character is not a ':' then append
// Else if check the next character to see if it is a ')'
// Else do nothing and append the character
if ( currentChar != ':' ) {
stringBuffer.append( currentChar );
}
else if ( currentChar == ':' ) {
int j = i + 1;
char nextChar = userText.charAt( j );

// Check the next character if it is an ')' then assume it is an emoticon
// and replace both the ':' and ')' with the image tag
// Else append the ':'
if ( nextChar == ')' ) {
stringBuffer.append( "<img src=\"url\">" );
i++;
}
else {
stringBuffer.append( currentChar );
}
}
else {
stringBuffer.append( currentChar );
}
}

amicus
06-27-2003, 06:50 PM
you know what? i just realized that this line isn't being used so leave it off :)
'boolean isEmoticon = false;'

Lotus
06-30-2003, 01:59 AM
I could try this if it works. thanks.