BufferedReader (Read Search terms tutorial)

I've been looking for a long time now at a way to remove a list of words from a string.

I've been using:
.replaceAll("Remove this", "");

The problem is my list of words to remove is large and i'm also having to use that list multiple times.

I've created a script from the Read Search Terms script which works great. That way when I find a word I need to be removed I can post it to my .txt file without any code.

My question/problem is hopefully an easy one I've been using (?i) to make it in-sensitive to case meaning it will remove caps and non-caps
How do I incorporate (?i)to work with my variable: wordstoremove

Also if there is a way to remove duplicate words from DESCRIPTION. I've tried a few methods but can't seem to get a functioning script

what I have now:
DESCRIPTION = DESCRIPTION.replaceAll(wordstoremove, "");

What I used to use:
DESCRIPTION = DESCRIPTION.replaceAll("(?i)remove this", "");

THanks for your help/patience

You just need to tweak the

You just need to tweak the "want to use" to

DESCRIPTION = DESCRIPTION.replaceAll("(?i)" + wordstoremove, "");

The one thing I haven't

The one thing I haven't tried...Thanks Jason. Is there a simple way that I can remove duplicate words? I've tried searching the net and came up with some pretty complex codes.

DESCRIPTION = string.Join(" ", DESCRIPTION.Split(' ').Distinct());

Error:

DESCRIPTION .Split ( ' ' ) -- Error in method invocation: Method Split( char ) not found in class'java.lang.String'
Untitled Extractor Pattern--DataRecord 11:

I'm hoping I just don't understand the formatting. I'm slowly learning.
Thanks again

I see problems in your line,

I see problems in your line, but not sure what you're trying to end up with in order to help you. You just want a String, or would a Map do?

I'm sorryI'm trying to

I'm sorry
I'm trying to eliminate all duplicates of the same literal words withing the variable DESCRIPTION for example "This is example example"

change to "This is an example"

I guess I really don't care how it is done or how many lines it takes as long as I can output my result to my .csv file

I've tried this line:

String deDup(String DESCRIPTION) {
return new LinkedHashSet(Arrays.asList(DESCRIPTION.split(" "))).toString().replaceAll("(^\\[|\\]$)", "").replace(", ", " ");
}

That doesn't seem to work either. It still returns the same result

http://stackoverflow.com/ques

http://stackoverflow.com/questions/6790689/remove-duplicate-values-from-a-string-in-java

Yes thank you for that

Yes thank you for that reference that is what I am trying to duplicate.
at

String s="Bangalore-Chennai-NewYork-Bangalore-Chennai";

public String deDup(String s) {
return new LinkedHashSet(Arrays.asList(s.split("-"))).toString().replaceAll("(^\\[|\\]$)", "").replace(", ", "-");
}

public static void main(String[] args) {
System.out.println(deDup("Bangalore-Chennai-NewYork-Bangalore-Chennai"));
}

The error message was: class bsh.ParseException (line 3): public-- Encountered "public" at line 3, column 1.

Here's a script that I made

Here's a script that I made work

import java.util.*;

deDup(String s)
{
        values = new ArrayList();
        String[] splitted = s.split("-");
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < splitted.length; ++i)
        {
            if (!values.contains(splitted[i]))
            {
                values.add(splitted[i]);
                sb.append('-');
                sb.append(splitted[i]);
            }
        }
        return sb.substring(1);
}

s = "Bangalore-Chennai-NewYork-Bangalore-Chennai";
s = deDup(s);
session.log("New string: " + s);