Solved

Javascript - issues with replacing text

Posted on 2013-12-15
6
353 Views
Last Modified: 2013-12-21
I am having issues with the replace in my javascript page...I have text that I am editing that is very long....its seems that the replace method doesnt work in large text segments

below is what I want replace...but the variable pre_final_decrypt is a very large character string for encryption..as you can image encryption strings can be very large...thanks


        var v_start_superhero = pre_final_decrypt.replace("!!!!!!!!!!!COMIC_BOOK//////////", "");
0
Comment
Question by:GlobaLevel
  • 3
  • 3
6 Comments
 
LVL 35

Expert Comment

by:Robert Schutt
Comment Utility
I think the size of the string shouldn't matter. The standard string replace function only replaces the first occurrence so try using a regular expression with the g option (for global):
var v_start_superhero = pre_final_decrypt.replace(new RegExp("!!!!!!!!!!!COMIC_BOOK//////////", "g"), "");

Open in new window

0
 
LVL 10

Author Comment

by:GlobaLevel
Comment Utility
good idea...but when I run it with the regex in there...it craps out.....do I need to import a library for the regex?
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
Comment Utility
No, that code should work "as is". I've set up a little example form on my website: http://schutt.nl/ee/Q_28318638/

Maybe you can try pasting your string in there? There's no submit button, it's not being saved anywhere, just being processed in your browser. Just 'tab' out of any input field after changing it to see the new values in the output fields.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Author Comment

by:GlobaLevel
Comment Utility
heres the encrypted string:

       
        "!!!!!!!!!!!START_COMIC//////////!!!!!!!!!!!STOP_STRIP//////////&END&END*****|.....E.....||.....n.....||.....t.....||.....e.....||.....r.....|"

should be

"Enter"
0
 
LVL 35

Expert Comment

by:Robert Schutt
Comment Utility
Hmm ok that's a bit different. If the first part is static you can get rid of that with substring or simple string replace, but if the different parts can be in the string at different positions then I guess here's how I would do this (based on the previous replace):
var v_start_superhero = pre_final_decrypt.replace(new RegExp("!!!!!!!!!!!START_COMIC//////////", "g"), "").replace(new RegExp("!!!!!!!!!!!STOP_STRIP//////////", "g"), "").replace(new RegExp("\&END\&END\\*{5}", "g"), "").replace(new RegExp("(\\|\\.{5}(.)\\.{5}\\|)", "g"), "$2");

Open in new window

The main new thing here is the last replace which takes care of taking the wanted letters out of the repeating patterns of pipe symbols and dots.
0
 
LVL 10

Author Closing Comment

by:GlobaLevel
Comment Utility
a
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now