0

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

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

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

AND tp.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'";
6
  • use replace function in javascript Commented Feb 12, 2013 at 10:05
  • 1
    @RuneFS: that implies that JavaScript is jQuery (Since both sides of a = sign can be switched around). What I'm trying to say is: jQuery is a JS library. Saying "JavaScript or jQuery" makes perfect sense, since there's a difference between using native JS and jQuery. Commented Feb 12, 2013 at 10:18
  • @Cerbrus well if you wanna be mathematically about it then (for the fun of it) for x is y to be symmetric as you imply then x is not y should also be symmetric. That is jQeury is not javascript and javascript is not jqueryshould both be either true or false. Which is not the case. Further the mathematical binary relation equality is also transitive so if the is was indeed a mathematical operation then "jquery is javascript" and "javascript is a scripting language" would also imply that "jquery is a scripting language" which is clearly not the case either :) Commented Feb 12, 2013 at 10:33
  • You're missing the point here, @RuneFS, instead you're nitpicking about my abuse of math. You make a comment about the title, and I state that the title makes sense because there is a difference between using jQuery and JS. You say JQ is JS, but that's totally irrelevant in the context of the question. Commented Feb 12, 2013 at 10:40
  • @Rune FS : you are also right, actually jquery is library file of javascript. AND This issue can be solve using both way but jquery reduce the lot of JS code. If I asked this question only for javascript then stackfollers give me answer in javascript. And I want just solution for that so both way is okay for me but jquery is first priority. whatever, just thanks for your suggestion and clear the things Commented Feb 12, 2013 at 11:36

1 Answer 1

5

Simple:

str = str.replace(/\btp\./g, '');

This uses a regex to search for all occurrences of tp\. in the string, and replaces them with a empty string, effectively removing it.
(The period is escaped, since that's a special character in regexes. It literally searches for tp..
The \b is a word boundary, making sure that tp. is at the start of a word.)

Or, the split/ join method:

str = str.split('tp.').join('');

This will split up the string at every occurrence of 'tp.' (Without copying that along), then join the array together, resulting in a string where 'tp.' was removed.

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

1 Comment

I'd use /\btp\./ just in case.

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.