String Replace

They have: 218 posts

Joined: Apr 2001

Hi there,

I want to use String.replace() to replace apostrophes in a string (with an equivalent symbol that won't cause javascript problems). What is a function to do that?

Thanks,

TM

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Tony,

I'm sort of confused. Are you asking for a javascript function that will replace quotes that may cause javascript problems????

Where is your text coming from? If server-side (a dbms, eg), why can't you handle it from that end? If client-side, why aren't you handling it before passing it (by escaping the quotes -- "He said: 'she said: \"Sometimes I\'m confused.\" ' "

Vinny

Where the world once stood
the blades of grass cut me still

They have: 218 posts

Joined: Apr 2001

>>Are you asking for a javascript function that will replace quotes that may cause javascript problems????

Yes. I have multiple interface views (Flash and HTML) connected to an app, each handling quotes differently, so the scenario becomes a little more complex.

TM

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Tony,

My question was somewhat sarcastic -- if javascript can read the string in order to fix it, then there is no need for the function.

Could you supply examples of what the text looks like, where it's coming from, and where it's being received -- a url? html?

Vinny

Where the world once stood
the blades of grass cut me still

They have: 218 posts

Joined: Apr 2001

I found a solution. Titles were appended to a string which was being transfered around, with different ways of presenting apostrophes. So I stopped moving the info around and queried the database (the place where all the data is stored), with an index ID. Longer route, but at least the client now gets to have apostrophes.

TM

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

TonyMontana wrote: I found a solution.

Sometimes the longer road is the better road Laughing out loud

Vinny

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.