Solved

Javascript - issues with replacing text

Posted on 2013-12-15
6
371 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Browser Chrome downloads colored link 5 41
Simple Total function not working 8 32
asp.net mvc5 6 17
html Uncheck Checkbox 2 12
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

821 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