0

guys! I've got a URL in which I want to encode every character but slashes "/". I've tried to use String.split() function, but it doesn't work as I'd like it to:

String url1 = "/images";
String url2 = "/images/";

url1.split("/"); // gives me {"", "images"}
url2.split("/"); // gives me the same array {"", "images"}, when I expect {"", "images", ""}

How can I get {"", "images", ""} array for string like "/images/" ? Maybe I need to use another regex?

2
  • 7
    use split("/",-1) to get trailing empty strings. but you should rather use the build ins for URL´s if you are trying to parse them. Commented Dec 3, 2015 at 7:49
  • 1
    See explanation here. Commented Dec 3, 2015 at 7:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.