Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] String.replace and arrays
- From: skyscanner at eircom.net (SkyScanner)
- Subject: [Javascript] String.replace and arrays
- Date: Sat Sep 24 03:15:27 2005
Why not just use an array such as
array("[s]mouth.gif[/s]", ":D", "[s]frown.gif[/s]", ":(",) etc then loop through it:
if (word == array[loop_counter]) {word = array[loop_counter+1]}
Tim in Ireland.
----- Original Message -----
From: Julien Nadeau
To: [JavaScript List]
Sent: Saturday, September 24, 2005 5:13 AM
Subject: Re: [Javascript] String.replace and arrays
My parsed string does work. It does replace the [s]mouth.gif[/s] by mouth.gif. What I am trying to do though if to have [s]mouth.gif[/s] replaced by ":D", [s]tongue.gif[/s] replaced by ":P" and so on for the 20 or so smileys. So I'm trying to figure out a way to have the .replace() return the value from an array or something similar, but nothing has worked so far, and I'm trying to stay away from having to replace them all by hand.
Julien Nadeau
junado@xxxxxxxxxx
Le 05-09-23 ? 21:31, Troy III Ajnej a ?crit :
Have you tried to alert your 'parsedString' to see what it returns,
It is posible that your replace string is escaping the : character ?!
----------------------------------------------------------------------------
From: Julien Nadeau <junado@xxxxxxxxxx>
Reply-To: "\[JavaScript List\]" <javascript@xxxxxxxxxx>
To: "[JavaScript List]" <javascript@xxxxxxxxxx>
Subject: [Javascript] String.replace and arrays
Date: Fri, 23 Sep 2005 19:14:01 -0400
Good evening,
I'm rather puzzled by something I've encountered while playing with the string.replace() regex function in JavaScript.
I have a string that contains text like this:
var string = "this is some text [s]mouth.gif[/s] and some more text [s]tongue.gif[/s]";
Where "[s]mouth.gif[/s]" and "[s]tongue.gif[/s]" refers to smiley images.
I'm trying to replace theses with their corresponding ASCII, such as ":D" and ":P".
Using string.replace(), I got this regular expression that spot the [s] tags and parse the content.
var parsedString = string.replace(/\[s\]([a-zA-Z0-9_\.]+)+\[\/s\]/gi, "$1");
However, I'm trying to get that $1 value and use it as an array index where I can store all corresponding ASCII values relative to filenames.
I've tried a few, but yet unsuccesful, solutions.
Anyone here has an idea on how to make this work?
Julien Nadeau
junado@xxxxxxxxxx
>_______________________________________________
>Javascript mailing list
>Javascript@xxxxxxxxxx
>https://lists.LaTech.edu/mailman/listinfo/javascript
----------------------------------------------------------------------------
Express yourself instantly with MSN Messenger! MSN Messenger Download today it's FREE!
_______________________________________________
Javascript mailing list
Javascript@xxxxxxxxxx
https://lists.LaTech.edu/mailman/listinfo/javascript
------------------------------------------------------------------------------
_______________________________________________
Javascript mailing list
Javascript@xxxxxxxxxx
https://lists.LaTech.edu/mailman/listinfo/javascript
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.LaTech.edu/pipermail/javascript/attachments/20050924/5e3c0a51/attachment.html
- Follow-Ups:
- [Javascript] String.replace and arrays
- From: Julien Nadeau
- [Javascript] String.replace and arrays
- References:
- [Javascript] String.replace and arrays
- From: Troy III Ajnej
- [Javascript] String.replace and arrays
- From: Julien Nadeau
- [Javascript] String.replace and arrays
- Prev by Date: [Javascript] String.replace and arrays
- Next by Date: [Javascript] String.replace and arrays
- Previous by thread: [Javascript] String.replace and arrays
- Next by thread: [Javascript] String.replace and arrays
- Index(es):