A java String variable whose value is
String path = "http://cdn.gs.com/new/downloads/Q22010MVR_PressRelease.pdf.null"
I want to remove the last four characters i.e., .null. Which method I can use in order to split.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think you want to remove the last five characters (‘.’, ‘n’, ‘u’, ‘l’, ‘l’):
Note how you need to use the return value – strings are immutable, so
substring(and other methods) don’t change the existing string – they return a reference to a new string with the appropriate data.Or to be a bit safer:
However, I would try to tackle the problem higher up. My guess is that you’ve only got the “.null” because some other code is doing something like this:
where
extensionis null. I would conditionalise that instead, so you never get the bad data in the first place.(As noted in a question comment, you really should look through the
StringAPI. It’s one of the most commonly-used classes in Java, so there’s no excuse for not being familiar with it.)