Solved

Javascript - issues with replacing text

Posted on 2013-12-15
6
390 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39720039
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
ID: 39720201
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
ID: 39720219
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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
LVL 10

Author Comment

by:GlobaLevel
ID: 39720516
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
ID: 39720552
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
ID: 39734162
a
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

688 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