Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

search for coded URL string "%06"

Posted on 2002-06-12
5
Medium Priority
?
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

636 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