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
Solved

get a value from a content string

Posted on 2004-04-25
10
284 Views
Last Modified: 2010-03-31
xmlurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2FagtGetDocsViewXML%3Fopenagent%26u%3Dc956395%26uname%3DJoe+Blogg%26start%3D1%26count%3D9999%26viewname%3Dfrmgicsissueview%26frmname%3D%26frmtype%3DView&xslurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2Fviewreport.xsl

I do have a method to decode the content string, however I need a method to pass in this content string and get the values for xmlurl and xslurl.

Thanks
pcorreya
0
Comment
Question by:pcorreya
  • 3
  • 2
  • 2
  • +1
10 Comments
 
LVL 7

Accepted Solution

by:
vbandaru earned 43 total points
ID: 10911717
The String Object has an overloaded method called indexOf. You should be able to use that in conjunction with substring to get the xmlurl and xslurl.

something like this.

String contentString="xmlurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2FagtGetDocsViewXML%3Fopenagent%26u%3Dc956395%26uname%3DJoe+Blogg%26start%3D1%26count%3D9999%26viewname%3Dfrmgicsissueview%26frmname%3D%26frmtype%3DView&xslurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2Fviewreport.xsl";

String xmlurl= contentString.substring(7,contentString.indexOf("xslurl")-1);

String xslurl= contentString.substring(contentString.indexOf("xslurl")+7);
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 41 total points
ID: 10912076
Or you can use regular expressions:

            String x = "xmlurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2FagtGetDocsViewXML%3Fopenagent%26u%3Dc956395%26uname%3DJoe+Blogg%26start%3D1%26count%3D9999%26viewname%3Dfrmgicsissueview%26frmname%3D%26frmtype%3DView&xslurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2Fviewreport.xsl";
            x = URLDecoder.decode(x, "UTF-8");
            final String RE = "xmlurl=(.+)\\?.+xslurl=(.+)";
            Pattern p = Pattern.compile(RE);
            Matcher m = p.matcher(x);
            if (m.matches()) {
                  System.out.println(m.group(1));
                  System.out.println(m.group(2));
            }
0
 
LVL 92

Expert Comment

by:objects
ID: 10914093
vbandaru is right, the only additional thing you may want to do is decode the urls:

import java.net.*;

public class extracturls
{
      public static void main(String[] args)
      {
            String contentString="xmlurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2FagtGetDocsViewXML%3Fopenagent%26u%3Dc956395%26uname%3DJoe+Blogg%26start%3D1%26count%3D9999%26viewname%3Dfrmgicsissueview%26frmname%3D%26frmtype%3DView&xslurl=http%3A%2F%2F127.0.0.1%2Fmydbs%2Fwipdesign.nsf%2Fviewreport.xsl";

            String xmlurl= URLDecoder.decode(contentString.substring(7,contentString.indexOf("xslurl")-1));

            String xslurl= URLDecoder.decode(contentString.substring(contentString.indexOf("xslurl")+7));
            
            System.out.println(xmlurl);
            System.out.println(xslurl);
      }
}
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:CEHJ
ID: 10914109
>>vbandaru is right

? So i'm wrong am i? ;-)

In any case, your comment is redundant - you obviously have not read the question:

>>I do have a method to decode the content string, ...
0
 
LVL 1

Author Comment

by:pcorreya
ID: 10914501
Thanks you all for your contribution, however it would be nice to have a class that I can use to pass it the content string and the lookup field and return its value.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 41 total points
ID: 10914808
try something like:

     public static String extractField(String contentString, String lookup)
     {
          String[] pairs = contentString.split("&");
          for (int i=0; i<pairs.length; i++)
          {
              String[] keyvalue = pairs[i].split("=");
              if (keyvalue[0].equals(lookup)) return keyvalue[1];
          }
          return null;
     }
0
 
LVL 1

Author Comment

by:pcorreya
ID: 10927241
objects, i am getting the message Method split(java.lang.String) not found in class java.lang.String
0
 
LVL 92

Expert Comment

by:objects
ID: 10927304
it only became available in 1.4.
you'll need to use StringTokenizer in previous versions.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom annotations 9 42
more than one jdk and one jre 1 50
Groovy problem when using SOAPUI : DispatchException occurred 7 58
Java: anonymous class 4 29
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

856 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