www.webdeveloper.com
Results 1 to 3 of 3

Thread: String finding and return

  1. #1
    Join Date
    Oct 2007
    Posts
    8

    String finding and return

    Hi, I'm not a java programmer, but I need some help.

    could anyone write a method take looks like this:



    public String getMatchedString(String text, String start, String end)


    the method should recive a string with a text, and the other parameters (start and end) are two string that it must find in the text, when he finds a String that starts with "start" and ends with "end" it should return a string with what is between them.

    exemple:

    getMatchedString("Name: John Rambo - Age: 21", "Name:" , "- Age: 21")

    should return "John Rambo"

    got it?

    thanks for just reading

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,136
    Its your lucky day..:-) enjoy....

    PHP Code:
    public String getMatchedString(String strToSearchFromString strStartsWithString strEndsWith) {
            
    String result=null;
            if(
    strToSearchFrom.startsWith(strStartsWith) && strToSearchFrom.endsWith(strEndsWith)){
                return 
    strToSearchFrom.substring(
                        
    strToSearchFrom.indexOf(strStartsWith)+strStartsWith.length(),
                        
    strToSearchFrom.indexOf(strEndsWith));
            }
            return 
    result;
        } 
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Oct 2007
    Posts
    8
    thanks mate.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles