Solved

search for coded URL string "%06"

Posted on 2002-06-12
5
175 Views
Last Modified: 2010-03-31
I've got a decoded URL string, and in that string there is an not-displayable-character encoded representing "%06",
question is: How do search for that not displayable charcter where I want to use it as a delimiter in methods like StringTokenizer(String str, String delim)?
Thanks.
0
Comment
Question by:tomboman
5 Comments
 
LVL 16

Expert Comment

by:heyhey_
ID: 7074850
you can decode it first and then it will take a single char.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7074878
I don't think that you can use
String.indexOf() with such a character. Instead of this I suggest using
StringTokenizer(String str, String delim = "%06")
with the encoded string and after that - decoding the returned tokens
0
 
LVL 35

Expert Comment

by:girionis
ID: 7074979
 The following should work:

String s = "hello%06world";
java.util.StringTokenizer st = new java.util.StringTokenizer(s, "%06");
while (st.hasMoreTokens())
{
     System.out.println(st.nextToken());
}

  and the output should be:

hello
world

  Hope it helps.
0
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 50 total points
ID: 7076145
Unfortunately, that example will also treat all occurrences of any one of these characters as a delimiter. This is because the delim argument to StringTokenizer really specifies a set of characters that act as delimiters, not a single group of characters that must be completely matched.

In a recent JavaWorld article that discussed this 'pitfall' (http://www.javaworld.com/javaworld/jw-09-2000/jw-0922-javatraps_p.html) the following code solution was given as an alternative:

public static String[] tokenize(String input, String delimiters, boolean delimiterAsGroup) {
    Vector v = new Vector();
    String toks[] = null;

    if (!delimiterAsGroup) {
        StringTokenizer t = new StringTokenizer(input, delimiters);
        while (t.hasMoreTokens())
            v.addElement(t.nextToken());
    } else {
        int start = 0;
        int end = input.length();

        while (start < end) {
            int delimIdx = input.indexOf(delimiters,start);
            if (delimIdx < 0) {
                String tok = input.substring(start);
                v.addElement(tok);
                start = end;
            } else {
                String tok = input.substring(start, delimIdx);
                v.addElement(tok);
                start = delimIdx + delimiters.length();
            }
        }
    }

    int cnt = v.size();
    if (cnt > 0) {
        toks = new String[cnt];
        v.copyInto(toks);
    }
     
    return toks;
}

Best regards,
Jim Cakalic
0
 

Author Comment

by:tomboman
ID: 7077457
Very detailed answer jim, thanks.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how do i compare an object based on two fields 6 54
eclipse argument 14 61
jar file executable 12 52
Crystal Reports Licensing Questions 4 12
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question