?
Solved

Javascript - issues with replacing text

Posted on 2013-12-15
6
Medium Priority
?
391 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 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

DFW AZURE MEETUP TONIGHT FRI 6PM

We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to dynamically set the form action using jQuery.
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).
Suggested Courses

752 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