Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3319744
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:51:39+00:00 2026-05-17T22:51:39+00:00

I need some help in adding the replace all functionality into my Flex project.

  • 0

I need some help in adding the replace all functionality into my Flex project. I would prefer doing this in a way that is as natural as possible.

What I want to achieve is to be able to run this code (with the Flex compiler) "aabbaaba".replaceAll("b","c") and get "aaccaaca". Also I want to chain replaceAll calls.
Note: I won’t be actually replacing bs with cs, but various string that will not be known at coding time!

What I don’t want:
1. Use regular expressions with the global flag. The tokens to replace are determined ad run time and transforming them into a regular expression isn’t straight forward.
2. Use the StringUtil.replace method. It’s a static method and chaining is ugly.
3. Chain split and join. Because it may be confusing for others when reading the code.
4. Disable strict type checking. I want to have type checking for the rest of my code.


Here is what I have so far:

String.prototype.replaceAll = function(replace:String, replaceWith:String):String{
    return this.split(replace).join(replaceWith);
}

And can be called like this:

"aababacaaccb"["replaceAll"]("b", "c")["replaceAll"]("c", "a");

Also, are there any recommendations against extending objects through the prototype? I will also accept an answer that has strong arguments against extending the String object through the prototype.

Thank you,
Alin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:51:39+00:00Added an answer on May 17, 2026 at 10:51 pm

    I think you got all the technical answers possible. I will elaborate in what I think is the best way to approach this language-wise.

    Prototypes are not recommended in an OOP language such as AS3 (mostly because they defy encapsulation). You imply that you don’t want something “confusing to others” (in relation to split.join); well, prototypes in AS3 are very confusing.
    Just as an example of this, a prototype declaration can be done from anywhere in your code, and as such is not obvious where it should reside. If “others” encounter “foo”.replaceAll() in your code, it’s not at all obvious where one can find that method and check what it really does.

    A static function amends this and is pretty straight forward. Sure, you need an extra argument, and you can’t really chain properly, but is this such a bad thing?

    If you need performance, split.join is the way to go. I would bet good money that more AS3 devs know about split.join than the use of prototypes.

    On the other hand, I think the most semantic and pragmatic way would be to use the own language method (hence my previous answer). You are trying to replace all needles in a string with another string in AS3, and for that the language has the String::replace method with the global flag. I’m pretty sure there is a way to easily parse and use any string in regexp.

    I concur that in some cases a helper method (like replaceAll) could be necessary, but I would strongly encourage you to not use prototypes, and instead use a more standard way, like StringUtil.replace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help adding conditions to a linq query. Take this small example
I am new to all the anonymous features and need some help. I have
I'm new to iPhone dev and need some help with adding subViews. I have
I need some help from the shell-script gurus out there. I have a .txt
I need some help regarding algorithm for randomness. So Problem is. There are 50
I need some help calculating Pi. I am trying to write a python program
I need some help with jQuery script again :-) Just trying to play with
I need some help ... I'm a bit (read total) n00b when it comes
Hi I need some help with the following scenario in php. I have a
I am getting a little confused and need some help please. Take these two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.