-4

I want to remove special characters from a String which is passed by a jsp file

I am receiving the value 2019/05/09 and I want to remove all the "/". Expected output - 20190509

How can I do this? Thanks for the time!

  • 6
    You realize that `2019/05/09` is a date and not a number, right? Would it even make sense to convert that to the number 20190509? Even if so you'd need to first parse and reformat the date (or at least remove the slashes) and then parse the result as an int. – Thomas May 09 '19 at 07:45
  • 3
    Just use a string replace function to strip out the "/" from the string – Anirudh Simha May 09 '19 at 07:45
  • 1
    Just split the string at `/` and then combine the different parts again to make a new string. Then parse that string as integer. Although it makes no sense to convert date to integer. – Navjot Singh May 09 '19 at 07:46
  • Not a duplicate but enough info to solve this, https://stackoverflow.com/questions/38934174/how-to-parse-date-string-into-integer-variables – Joakim Danielson May 09 '19 at 07:53
  • Please rethink what you're doing, because just trying to convert a date to a number and think you can use it in a meaningful way is a mistake. You need to convert to a date (eg a `java.time.LocalDate`) and use that for your calculations. – Mark Rotteveel May 09 '19 at 18:24

2 Answers2

0

You need to remove the '/' and then do the parsing.

int checkin = Integer.parseInt(request.getParameter("checkin").replace("/",""));

Sameer
  • 757
  • 1
  • 14
  • 35
-1

Hi i assume that the datatype that you get in the request parameter is String.

You may use this.

int checkin = Integer.valueOf(request.getParameter("checkin").replace("/",""));