Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript - issues with replacing text

Posted on 2013-12-15
6
Medium Priority
?
396 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

610 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