Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

String Extraction?

aveachaveach Member Posts: 5
Hi,
What is the method i need to use to extract a string from another string? For example if a user enters the String "I wish my code worked"
it would extract a string i specify such as "why do i work" or i guess it could return true if the inputed string contains "why do i work" in any order. I know that some objects have a contains() method but i am not familiar with this or even if this method may work?Any ideas?Thanks


Comments

  • RobF11RobF11 Member Posts: 6
    : Hi,
    : What is the method i need to use to extract a string from another string? For example if a user enters the String "I wish my code worked"
    : it would extract a string i specify such as "why do i work" or i guess it could return true if the inputed string contains "why do i work" in any order. I know that some objects have a contains() method but i am not familiar with this or even if this method may work?Any ideas?Thanks
    :
    :
    :

    you could convert the original String to a StringBuffer then have a for loop with a for loop in it, the outside for loop goes through each letter of the String you wish to extract and the inside for loop goes through each letter of the original String which is now a StringBuffer,
    when it finds a match it removes the letter from the StingBuffer
    if you don't want my idea for the code, don't scroll down, but if u want it, do scroll down


























    StringBuffer = new StringBuffer();
    String temp="";
    for(int i=0; i<<String you wish to extract>.length(); i++)
    for(int q=0; q<<converted String>.length(); q++)
    if(.charAt(i)==.charAt(q)){
    temp+=.remove(q);
    q=.length()+5;
    }

    something like that


Sign In or Register to comment.