StringUtils not working even with included imports

520 views Asked by At

I trying the code into my application to remove multiple unnecessary spaces:

while (cleantext.indexOf("  ") != -1)
     cleantext = StringUtils.replace(cleantext, "  ", " ");

But got this message error:

Main.java:101: error: cannot find symbol
    line = StringUtils.replace

I did following imports and neither worked so far -- lang and StringUtils:

import java.lang.*;
import org.apache.commons.lang3.StringUtils;

Either way the problem does not go away. So how to get this fixed?

Edited:

Thanks for the suggestions. I am running on command line on Linux terminal.

I was using the command:

$ javac -cp "./" Main.java

Then changing the command to:

$ javac -cp jar1  Main.java

Gave me the error:

Main.java:8: error: package org.apache.commons.lang3 does not exist
import org.apache.commons.lang3.StringUtils;

Final edit:

I replaced the "while" content in the code for the following command line as example previously given on StackOverflow:

str=str.trim().replaceAll("(\\s)+", "$1");

That did the trick. Problem solved! Thanks a ton for all the suggestions.

0

There are 0 answers