Can anybody Send me Small java program for String manipulation

Posted on 2005-04-06
Last Modified: 2012-05-05
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
xx xxxx xxxx xxxx xxx xxxxx xxxx xxxx xxxx xxx xxx xxx xxx xxxx xx
xxx xxxx xxx x CrystalEnterprise_Hyperlink/ xxx xxx xxx xxx xxx xxx xxxxx xxx xxx xxx xxx xxx xxx xxx xx xxx xx xx
CrystalEnterprise_Hyperlink/ 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

Question by:navarathna
    LVL 5

    Accepted Solution

    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)
          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;
            requiredStringsArray.addElement(str.substring(firstIndexOfColon, lastIndexOfColon + 1));
            String s = str.substring((lastIndexOfColon + 1), str.length());

    // now call that method passing your string
    String yourString = "CrystalEnterprise_Hyperlink/ xxxx xxx x CrystalEnterprise_Hyperlink/ ";

        getStr(yourString );

    //-- display extracted stings
        for(int i = 0; i < requiredStringsArray.size(); i++)
    LVL 86

    Expert Comment

    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

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    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 …
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
    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…

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now