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

x
?
Solved

get a value from a content string

Posted on 2004-04-25
10
Medium Priority
?
290 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
[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
  • 3
  • 2
  • 2
  • +1
10 Comments
 
LVL 7

Accepted Solution

by:
vbandaru earned 172 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 164 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 164 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.
Suggested Courses

618 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