[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Can anybody Send me Small java program for String manipulation

Hi experts

      iam new to java...
      and iam supposed to write a java program with manipulates the   string(http reponse text)  which contains many objectID's

  My method must return each objectid once when i call in the loop

  the response text looks like the following and i must return one objid value when i call once  ,plz note that the following text is stored in string
_______________________________________________________
xxx xxx xxxxxxxxx xxx xxx xxx xxx
xxx  xxxx   xxx xxx  xxx xx xx  xx  xxx xxx xxx xxx xxx xx xxx
CrystalEnterprise_Hyperlink/view.do?objId=32423
xx xxxx xxxx xxxx xxx xxxxx xxxx xxxx xxxx xxx xxx xxx xxx xxxx xx
xxx xxxx xxx x CrystalEnterprise_Hyperlink/view.do?objId=57653 xxx xxx xxx xxx xxx xxx xxxxx xxx xxx xxx xxx xxx xxx xxx xx xxx xx xx
CrystalEnterprise_Hyperlink/view.do?objId=99999 xxx xxx xxxx xxx
xxxx xxx xxxx xxx xxx
_______________________________________________________

there are many "object ids" in the response text and the "pattern" will be the same for all the objects ids..

thanks in advance
-navrathna












 
0
navarathna
Asked:
navarathna
1 Solution
 
NaeemgCommented:
i've made a method for u. try the following ,

//define these globally in ur class.

  Vector requiredStringsArray = new Vector();
  int firstIndexOfColon = -1;
  int lastIndexOfColon = -1;

// add followin method
  void getStr(String str)
  {
    //System.out.println(str);
      firstIndexOfColon = str.indexOf("objId=");
      if(firstIndexOfColon > -1)
      {
        for(int i = firstIndexOfColon + 1; i < str.length(); i++)
        {
          if((str.charAt(i) == ' ')) // blank space found
          {
            lastIndexOfColon = i;
            break;
          }
        }
       
        requiredStringsArray.addElement(str.substring(firstIndexOfColon, lastIndexOfColon + 1));
        String s = str.substring((lastIndexOfColon + 1), str.length());
        //System.out.println(s);
        getStr(s.trim());
      }    
  }


//
// now call that method passing your string
String yourString = "CrystalEnterprise_Hyperlink/view.do?objId=32423xxx xxxx xxx x CrystalEnterprise_Hyperlink/view.do?objId=57653 ";

    getStr(yourString );

//-- display extracted stings
    for(int i = 0; i < requiredStringsArray.size(); i++)
      System.out.println(requiredStringsArray.elementAt(i));
0
 
CEHJCommented:
navarathna, you're obviously new to this site too. The idea of it is not to provide questioners with a custom code/ homework writing service, but rather to help them with code they've already produced.

You need to read the response into a buffer and then search it
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now