Home > Software engineering >  How to replace Line Tabulation (\\u000B or ) in String using Java?
How to replace Line Tabulation (\\u000B or ) in String using Java?

Time:02-11

  • The Data looks somewhat like following in database: ()

enter image description here

  • When record is fetched from database and rest service responded it looks like :

    ICT0637256 Onboarding questionnaire for internal transfers & dashboard\u000BOnboarding
    
  • Another wrapper service which returns soap response; when call this rest service, then it returns following response :

    <ns7:TaskDescription>ICT0637256 Onboarding questionnaire for internal transfers &amp; dashboard&#11;Onboarding</ns7:TaskDescription>
    

I searched on internet and found \u000B is line tabulation.

Now on soap service level, i am trying to replace character comes from Rest Service:

  public String replaceUnnecessaryCharacters(String text) {
        if(StringUtils.isNotEmpty(text)) {
            text = text.replaceAll("\\\\u000B", " ");
            text = text.replaceAll("&#11;", " ");
            text = text.replaceAll("<0x0b>", " ");
            text = text.replaceAll("\\^K", " ");
        }
        return text;
    }

    if(task.getProjectId() == 5130764) {
        LOG.info("getTasks: DescriptionDetails:5130764"   task.getDescription()); //<-- This comes from Rest API in code
        LOG.info("getTasks: DescriptionDetails:5130764"   replaceUnnecessaryCharacters(task.getDescription())); <--- Here it doesn't show \u00B but blank space
    }soapResponsetsk.setTaskDescription(replaceUnnecessaryCharacters(task.getDescription()));
  • When i copy it in notepad, it looks like

enter image description here

  • When i copy it to VI Editor in linux then it shows ^K

I am like lost how to replace this character using Java? Can you please suggest how to fix the same?

CodePudding user response:

Since you are not really using any of regex syntax (like * quantifiers, \w character classes, etc.) instead of replaceAll you can use replace method.

Also since you want to replace single character with another character you can use replace(char oldChar, char newChar) like

text = text.replace('\u000B', ' ');
  • Related