0

How can remove the 'tp.','ta.' and 'tta.' from below string from each place where it is coming

str = " tp.FirstName, tp.FamilyName, ta.DOB, tta.TypeOfLocation
WHERE

tp.DateStamp BETWEEN '2012-02-12 15:13:00' AND '2013-02-12 15:13:00'

AND tta.db_name_id =21
AND

tp.FirstName = 'Darlene'";

I need result as below:

FirstName, FamilyName, DOB, TypeOfLocation
WHERE

DateStamp BETWEEN '2012-02-12 15:13:00' AND '2013-02-12 15:13:00'

AND db_name_id =21
AND

FirstName = 'Darlene'";

Note: I have asked same question but this time I am using multiple removing string. Please assist me

1
  • I was tried .replace but something wrong there. now it is fixed thru 2nd answer. Commented Feb 13, 2013 at 6:56

5 Answers 5

3

Can try this:

str.replace(/(tp\.)|(ta\.)|(tta\.)/g, '');

Fiddle : check the console

Sign up to request clarification or add additional context in comments.

1 Comment

This won't work as . will match any character. Your output will have DateSp BETWEEN instead of DateStamp BETWEEN.
2
    "aaa tp.bbb tf.ccc  tq.ddddd".replace(/[(tp\.)(tf\.)(tq\.)]/g, "")

    "aaa bbb ccc  ddddd"

But. Regular expressions can be an order of magnitude slower than 'normal' string operations. There are up to 10 browsers and 5 platforms these days where this has to be tested. Hard to believe but this example might be much faster:

     "aaa tp.bbbb  tf.ccc".split("tp.").join("").split("tf.").join("")
     "aaa bbbb  ccc"

Try and test. I would test on very large strings on mobile browsers first. It all depends WHERE do you perceive the primary usage is going to be.

Comments

1

Use this:

str = str.replace(/tp\./g,"").replace(/tta\./g,"").replace(/ta\./g,"");

Comments

0

Try str.substring(str.indexOf(".")) for each word in the string.

Comments

-1
var newstring = str.replace(".tp","").replace(".ta","").replace("tta.","");

that would work

1 Comment

Replace (when used with strings) only replaces the first occurrence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.