Hello!

I write a simple java program. The user will give a URL adres which have some flags. I will parse the URL by this flags.

For example the user will give www.exampledomain.com/abc/[[FLAG1]]/abc_[[FLAG2]]gfc
I need to parse load to string parsing the URL:
String[1]=www.exampledomain.com/abc/
String[2]=/abc_
String[3]=gfc

I need to ask two questions here:

First
new Scanner("www.exampledomain.com/abc/[[FLAG1]]/abc_[[FLAG2]]gfc").useDelimiter("[[|]]");
my_scanner.next(); ==> why returns me null?

Second, which character i must use for flags? Which characters are not allowing on URL? [ or \ or something else? (I use on example [[ ]] because i did not know a character will not catch by delimiter)

Thank you!

It executes for me:

Scanner my_scanner = new Scanner("www.exampledomain.com/abc/[[FLAG1]]/abc_[[FLAG2]]gfc").useDelimiter("[[|]]");
      System.out.println(my_scanner.next()); //==> www.exampledomain.com/abc/[[FLAG1]]/abc_[[FLAG2]]gfc

It executes for me:

Scanner my_scanner = new Scanner("www.exampledomain.com/abc/[[FLAG1]]/abc_[[FLAG2]]gfc").useDelimiter("[[|]]");
      System.out.println(my_scanner.next()); //==> www.exampledomain.com/abc/[[FLAG1]]/abc_[[FLAG2]]gfc

Yes you tell true. I saw it now it returns all the string. But i did not want that.

my_scanner.next() must not return all the string as you show me:

System.out.println(my_scanner.next()); //==> www.exampledomain.com/abc/[[FLAG1]]/abc_[[FLAG2]]gfc

In first use my_scanner.next() must return the www.exampledomain.com/abc/, on the second use /abc_, and on the third use gfc.


--------

I test it now. useDelimiter can parse the string if i send to useDelimiter method any character. That means useDelimiter does not allow [ or ] character. I don't know what to do...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.